Microsoft KB Archive/181441

= WD98: Sample VBA Code to Set, Retrieve Summary Information =

Article ID: 181441

Article Last Modified on 4/14/2006

-

APPLIES TO


 * Microsoft Word 98 for Macintosh

-



This article was previously published under Q181441





SUMMARY
In Microsoft Word, you can use Microsoft Visual Basic for Applications to access the summary information in the Document Properties dialog box (on the File menu, click Properties) and then display the information in a message box, insert the information into the active document, or store the values within a variable.



MORE INFORMATION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. To retrieve or set values on the Summary tab of the Document Properties dialog box, use the following literal string arguments or property constants with either of the two methods below.   Literal String Arguments             Property Constants --  Title                                wdPropertyTitle Subject                             wdPropertySubject Author                              wdPropertyAuthor Manager                             wdPropertyManager Company                             wdPropertyCompany Category                            wdPropertyCategory Keywords                            wdPropertyKeywords Comments                            wdPropertyComments Hyperlink base                      wdPropertyHyperlinkbase

Method 1: Use the BuiltInDocumentProperties Property
Use the BuiltInDocumentProperties property to set and return summary information for the active document. You can specify which value to set or retrieve by referencing the argument through a built-in constant or a literal string. The following sample code uses the wdPropertyTitle constant to retrieve the title for the active document and displays the result in a message box. Sub GetSetDocProps

If Documents.Count > 0 Then

Dim dp As Object Set dp = ActiveDocument.BuiltInDocumentProperties

' Retrieve and display the active document's        ' title by using the constant "wdPropertyTitle." MsgBox dp(wdPropertyTitle)

End If

End Sub The following sample code uses a literal string to define the keywords for the active document: Sub SetDocProps

If Documents.Count > 0 Then

Dim dp As Object Set dp = ActiveDocument.BuiltInDocumentProperties

' Set KeyWords for the active document by        ' using a literal string. dp("KeyWords") = "Summary Information Example Macro" ActiveDocument.Save

End If

End Sub

Method 2: Use the Dialogs Collection to Set and Return Values
Use the Dialogs collection to set and return values for the active document's summary information.

Before you return or change a built-in dialog box setting, you need to identify the individual dialog box. To do this, use the Dialogs collection and a WdWordDialog constant that identifies the dialog box. The following Visual Basic statement returns the Dialog object that refers to the Summary tab of the Document Properties dialog box. Set myDialog = Dialogs(wdDialogFileSummaryInfo) You can set or retrieve the following literal string arguments without displaying the Summary tab when a document is open.

Title

Subject

Author

Manager

Company

Category

Keywords

Comments

Hyperlinkbase

The following sample macro retrieves the current value of the Title string, places this value in a variable string, and sets a new value without displaying the Properties dialog box. Sub SetSummaryInfo

If Documents.Count > 0 Then

Dim dp As Object Set dp = Dialogs(wdDialogFileSummaryInfo)

' Retrieve value of Title and store in a variable. a$ = dp.Title

' Set Title to a new value. dp.Title = "My Title"

' Set the value without showing the dialog box. dp.Execute

' Save the changes. ActiveDocument.Save

End If

End Sub The following sample macro sets a new value for Title and displays the Properties dialog box. Sub SetSummaryInfo

If Documents.Count > 0 Then

Dim dp As Object Set dp = Dialogs(wdDialogFileSummaryInfo)

' Set Title to a new value. dp.Title = "My Title"

' Set the value. dp.Execute

' Save the changes. ActiveDocument.Save

' Display the dialog box. ' Note: Using the Display method will not keep changes ' manually entered into the dialog box. To keep changes ' manually entered in the dialog box, use the Show method. dp.Display

End If

End Sub For additional information, please see the following article in the Microsoft Knowledge Base:

173707 OFF97: How to Run Sample Code from Knowledge Base Articles

