ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 5885|回复: 1

[求助] VBA批量修改ppt文件的属性(作者、主题、标题、关键字等信息)

[复制链接]

TA的精华主题

TA的得分主题

发表于 2011-7-14 15:42 | 显示全部楼层 |阅读模式
Option Explicit

Dim ArrFiles(1 To 10000)
Dim cntFiles%

Sub SetDocss()

'Dim myPageSetup As PageSetup

'Dim myDialog As FileDialog

Dim oFile As Variant

Dim FolderPath As String

Dim oDoc As Presentation

'Dim rngHeaders As Range

'Dim rngFooters As Range

'Dim myRange As Range

'Dim docCount As Integer

Dim myTitle As String

Dim mySubject As String

Dim myAuthor As String

Dim myManager As String

Dim myCompany As String

Dim myComments As String

Dim mykeyWords As String

Dim mycategory As String

Dim lastauthor As String




On Error Resume Next

'以下定义文档属性

myTitle = "http://www.XXXXs.com"

mySubject = "http://www.XXXs.com"

myAuthor = "http://www.XXXs.com"

myManager = "http://www.XXXs.com"

myCompany = "http://www.XXXs.com"

myComments = "http://www.XXXs.com"

mykeyWords = "http://wwws.com"

mycategory = "http://www.XXXs.com"

lastauthor = "http://www.XXXs.com"

Dim Rsp
Dim strPath$
'Dim i%
'Set fso = CreateObject("Scripting.FileSystemObject")
Dim fso As New FileSystemObject, fd As Folder
strPath = InputBox("请输入要修改的文件夹地址,以\结尾:", "")
cntFiles = 0
Set fd = fso.GetFolder(strPath)
SearchFiles fd

Rsp = MsgBox("共有ppt文件" & cntFiles & "个,确定要修改", vbYes)
'Application.ScreenUpdating = False


For Each oFile In ArrFiles
'在所有选取项目中循环
Set oDoc = Presentations.Open(FileName:=oFile, WithWindow:=msoFalse)



With oDoc.BuiltInDocumentProperties

.Item("title").Value = myTitle

.Item("subject").Value = mySubject

.Item("author").Value = myAuthor

.Item("manager").Value = myManager

.Item("company").Value = myCompany

.Item("comments").Value = myComments

.Item("keywords").Value = mykeyWords

.Item("category").Value = mycategory

.Item("timelastsaved").Value = lastauthor

End With

oDoc.Close

Next


'End With

End Sub
Sub SearchFiles(ByVal fd As Folder)
Dim fl As File
Dim sfd As Folder
For Each fl In fd.Files
If UCase(Right(Trim(fl), 3)) = "PPT" Then
cntFiles = cntFiles + 1
ArrFiles(cntFiles) = fl.Path
End If
Next fl
If fd.SubFolders.Count = 0 Then Exit Sub

For Each sfd In fd.SubFolders
SearchFiles sfd
Next
End Sub
'----------------------
大家看看有什么问题,就是修改不成功...
我认为主要是
.Item("title").Value = myTitle这部分的事,在word中是.Item(wdPropertyTitle) = myTitle这样实现的,但是不知道ppt中是啥,阅读这个帮助如果演示文稿的作者为“Jake Jarmel”,本示例为该文稿设定内置文档属性“Category”的值。

With Application.ActivePresentation.BuiltInDocumentProperties
    If .Item("author").Value = "Jake Jarmel" Then
        .Item("category").Value = "Creative Writing"
    End If
End With
改用.Item("title").Value = myTitle,但是没有修改成功,有会的大师帮助下小弟,不胜感激!~

TA的精华主题

TA的得分主题

 楼主| 发表于 2011-7-14 16:16 | 显示全部楼层
自己搞的了,原来修改后关闭之前没有保存
End With
oDoc.save
oDoc.Close

Next
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-24 10:30 , Processed in 0.024313 second(s), 7 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表