Accessing DocProperty from VBA

P

Peter Clark

I wish to do the following, and I am having a hard time figuring out
how from the documentation:

Read the current value of custom DocProperty items from Word VBA(named
MyFormattedDate and MyUnformattedDate)

Update the value of these same DocProperty items from Word VBA

Thanks to all
 
C

Chuck

Use
ActiveDocument.CustomDocumentProperties("MyFormattedDate").Value
to both read and write the value.

You could add some testing code to make sure the variables are in the
document if there's a possibility that they might not be, eg

Dim docProp As DocumentProperty
Dim blnFound As Boolean

blnFound = False

For Each docProp In ActiveDocument.CustomDocumentProperties
If docProp.Name = "MyFormattedDate" Then
blnFound = True
End If
Next docProp

With ActiveDocument

If blnFound = False Then
.CustomDocumentProperties.Add _
Name:="MyFormattedDate", _
Value:="MyValue"
Else
.CustomDocumentProperties("MyFormattedDate").Value = "x/x/xx"
End If

End With
 
Top