D
Derrick
Hi All
This is my first dip into VBA, so apologies if the question is trivial.
I am wanting to add the same set of custom properties to a large number of
documents, and hoped the following code (synthesized from various examples)
would work.
The problem is that the SAVE statement does not have any effect, although
the CLOSE statement does.
If I interrupt execution before the CLOSE, I see that the custom property
has been added successfully. The debugging display before the SAVE shows a
value of TRUE for ActiveDocument.Saved.
What should I do to SAVE the document?
Thanks & regards
Derrick
(Code follows:
Public Sub AddProperty()
' Display FileOpen dialogue box to select file
If Dialogs(wdDialogFileOpen).Show = -1 Then
' OK button selected, process file
With ActiveDocument.CustomDocumentProperties
.Add Name:="MyNewProperty", _
LinkToContent:=False, _
Type:=msoPropertyTypeString, _
Value:="My new value"
' Debugging: following line displays a value of "True"
MsgBox (ActiveDocument.Saved)
ActiveDocument.Save
ActiveDocument.Close
'Also tried following option to save document
'ActiveDocument.Close SaveChanges:=wdSaveChanges
End With
End If
End Sub
This is my first dip into VBA, so apologies if the question is trivial.
I am wanting to add the same set of custom properties to a large number of
documents, and hoped the following code (synthesized from various examples)
would work.
The problem is that the SAVE statement does not have any effect, although
the CLOSE statement does.
If I interrupt execution before the CLOSE, I see that the custom property
has been added successfully. The debugging display before the SAVE shows a
value of TRUE for ActiveDocument.Saved.
What should I do to SAVE the document?
Thanks & regards
Derrick
(Code follows:
Public Sub AddProperty()
' Display FileOpen dialogue box to select file
If Dialogs(wdDialogFileOpen).Show = -1 Then
' OK button selected, process file
With ActiveDocument.CustomDocumentProperties
.Add Name:="MyNewProperty", _
LinkToContent:=False, _
Type:=msoPropertyTypeString, _
Value:="My new value"
' Debugging: following line displays a value of "True"
MsgBox (ActiveDocument.Saved)
ActiveDocument.Save
ActiveDocument.Close
'Also tried following option to save document
'ActiveDocument.Close SaveChanges:=wdSaveChanges
End With
End If
End Sub