Microsoft KB Archive/185513

= WD98: Sample VBA Macro to Count Number of Pages in Document =

Article ID: 185513

Article Last Modified on 6/17/2005

-

APPLIES TO


 * Microsoft Word 98 for Macintosh

-



This article was previously published under Q185513





SUMMARY
The article provides two sample Visual Basic for Applications procedures that return the total number of pages in the current document.



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. Method 1 uses the wdBuiltInProperty class constant wdPropertyPages; Method 2 uses a literal value.

Method 1: Using a Word Constant
Sub GetNumberOfPages ActiveDocument.Repaginate MsgBox ActiveDocument.BuiltInDocumentProperties(wdPropertyPages) End Sub NOTE: To see a list of the wdBuiltInProperty constants, follow these steps:
 * 1) Press ALT+F11 to open the Visual Basic Editor.
 * 2) Press F2 to display the Object Browser.
 * 3) Type wdbuiltinproperty, and then click Search

Method 2: Using Literal Value
Sub GetNumberOfPages ActiveDocument.Repaginate MsgBox ActiveDocument.BuiltInDocumentProperties("Number of Pages") End Sub NOTE: For more information about literal values, from the Visual Basic Editor click the Office Assistant, type document property object, click Search, and then click to view "DocumentProperty Object."

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If the Assistant is not able to answer your query, please see the following article in the Microsoft Knowledge Base:

176476 OFF: Office Assistant Not Answering Visual Basic Questions

