【发布时间】:2018-02-20 03:47:01
【问题描述】:
我正在尝试将一些自定义文档属性添加到 word 文档文件夹中。
我知道循环本身可以正常工作,因为我使用具有不同代码的相同循环来修改并更新预先存在的自定义文档属性。
添加自定义文档属性的代码也有效,我通过在它自己的宏中为单个文档运行它来测试它,效果很好。
由于循环有效并且循环中的代码也有效,我就是不知道它有什么问题。
代码如下:
Sub add_custom_docproperties()
Dim file
Dim path As String
Dim filepath As Variant
filepath = InputBox("Please enter the filepath for the files you want to
update.", "Input Filepath", "Copy filepath here...")
Select Case StrPtr(response)
Case 0
endednotification = MsgBox("The macro has been ended.", , "Notification")
Exit Sub
Case Else
End Select
path = filepath & "\"
file = Dir(path & "*.*")
'Application.ScreenUpdating = False
Do While file <> ""
Documents.Open FileName:=path & file
Check = MsgBox(path & file, , "Check")
ActiveDocument.CustomDocumentProperties.Add Name:="firstdocprop",
_LinkToContent:=False, Type:=msoPropertyTypeString, Value:="The First One"
ActiveDocument.CustomDocumentProperties.Add Name:="seconddocprop",
_LinkToContent:=False, Type:=msoPropertyTypeString, Value:="Second"
ActiveDocument.CustomDocumentProperties.Add Name:="thirddocprop",
_LinkToContent:=False, Type:=msoPropertyTypeString, Value:="Third"
'original example from:
'https://msdn.microsoft.com/en-us/vba/office-shared-vba
/articles/documentproperties-add-method-office
ActiveDocument.Save
ActiveDocument.Close
'set file to next in Dir
file = Dir()
Loop
'Application.ScreenUpdating = True
MsgBox "The macro is complete."
End Sub
如您所见,我对我从 msdn 尝试的第一个示例进行了评论,并对其进行了修改。
提前感谢您的帮助,即使您可以向我指出一个资源,解释我哪里出了问题或类似的东西。
【问题讨论】: