WD: How to Access the Summary Info Dialog Box from a Macro

ID: Q85168

1.x 2.x 6.00 6.00a 6.00c 7.00 7.0a | 6.00 6.0.1

WINDOWS                            | MACINTOSH
kbusage kbmacro

The information in this article applies to:

SUMMARY

In Microsoft Word for Windows, you can access the information in the Summary Info dialog box using the Microsoft WordBasic macro language and then post the information in a message box or insert the information into the active document.

MORE INFORMATION

To obtain the value of any field in the Summary Info dialog box, use the GetCurValues statement to access the information, then assign a string variable (A$) to the value of the field desired. The following macro displays the number of words, characters, and pages in the active document:

Word 7.x, 6.x and 2.x

Sub MAIN
   FileSummaryInfo .Update
   Dim dlg As Dialog FileSummaryInfo
   GetCurValues dlg
   A$ = dlg.NumWords
   B$ = dlg.NumChars
   C$ = dlg.NumPages
   MsgBox "Words =" + A$ + Chr$(160) + "Characters = " + B$ \ 
   + Chr$(160)  + " Pages ="  + C$
End Sub

If you are using Word version 1.x for Windows, change the two occurrences of FileSummaryInfo to EditSummaryInfo. The .Update argument for the FileSummaryInfo command updates the summary information so that the number of words, number of characters, and number of pages are most accurate.

Additionally, you can use a similar macro to insert the contents of fields within the Summary Info dialog box at the insertion position in the document. The following macro inserts the Title, Subject, and Author text as it appears in the Summary Info dialog box:

Word for Windows 6.0 and 2.0

Sub MAIN
   FileSummaryInfo .Update
   Dim dlg As Dialog FileSummaryInfo
   GetCurValues dlg
   A$ = dlg.Title
   B$ = dlg.Subject
   C$ = dlg.Author
   Insert "Title:" + Chr$(160) + A$
   InsertPara
   Insert "Subject:" + Chr$(160) + B$
   InsertPara
   Insert "Author:" + Chr$(160) + C$
   InsertPara
End Sub

Word version 6.0 for Windows includes the following new parameters for the FileSummaryInfo statement:

   .FileSize
   .NumParas
   .NumLines

If you are using Word version 1.x for Windows, change the two occurrences of FileSummaryInfo to EditSummaryInfo.

Note: "Using WordBasic" for Word version 2.x for Windows and the online documentation incorrectly list the following arguments as numbers instead of text variables:

   .NumPages
   .NumWords
   .NumChars

Note: Microsoft provides macros "as is" without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

For information about how to do this in Word 97, please see the following article(s) in the Microsoft Knowledge Base:

   ARTICLE-ID: Q158768
   TITLE     : Sample VB Code to Set, Retrieve Summary Information

REFERENCES

"Using WordBasic," by WexTech Systems and Microsoft, page 209

Kbcategory: kbusage kbmacro KBSubcategory: Additional reference words: winword2 1.0 1.1 1.1a 2.0a 1.00 1.10 1.10a 2.00 7.00 word95 word7 word6 winword 2.00a msgbox author title subject insert macword 6.0.1 winword 7.00a

Keywords          : kbmacro kbmacroexample winword ntword macword 
Version           : WINDOWS:2.0,2.0a,2.0a-CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0,7.0a; MACINTOSH:6.0,6.0.1,6.0.6.0.1a

Last Reviewed: February 4, 1998