Discussion Locked

Word VBA6 programming issue

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I would like to store the results of a Word VBA string function into one of the optional Fields that can be selected either in the Header or Footer. One of File Properties'constants such as "Client" in the "Custom" tab or "Author" in the "Summary" tab would be great but how do I go about programming that?

3 replies

by dklippert

This from the VBA Editor Help file (use the Object browser to look for CustomDocumentProperties):

Example
This example inserts a list of custom built-in properties at the end of the active document.

Set myRange = ActiveDocument.Content
myRange.Collapse Direction:=wdCollapseEnd
For Each prop In ActiveDocument.CustomDocumentProperties
With myRange
.InsertParagraphAfter
.InsertAfter prop.Name & "= "
.InsertAfter prop.Value
End With
Next
This example adds a custom built-in property to Sales.doc.

thename = InputBox("Please type your name", "Name")
Documents("Sales.doc").CustomDocumentProperties.Add _
Name:="YourName", LinkToContent:=False, Value:=thename, _
Type:=msoPropertyTypeString

by geoff_h

Thanks for your responsiveness. The second solution worked all the time the Property was "missing" though there were run-time errors trying to .Add when the Propety was already there but needed updated. What is the solution to that problem?

This discussion is closed to new replies.