Microsoft KB Archive/92929

{|
 * width="100%"|

WD: Macros to Count the Number of Document Paragraphs and Lines

 * }

Q92929

-

The information in this article applies to:


 * Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
 * Microsoft Word for Windows, versions 7.0, 7.0a
 * Microsoft Word for the Macintosh, versions 6.0, 6.0.1, 6.0.1a

-

SUMMARY
The number of paragraphs and lines in a document are counted and displayed in the Document Properties dialog box (Word versions 7.x) or in the Summary Info dialog box of earlier Word versions. To access this information from a macro, see the following examples.

MORE INFORMATION
NOTE: Microsoft provides macros &quot;as is&quot; 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.

Word Versions 6.x and 7.x
To return the number of paragraphs in a document, use the following macro:

  Sub MAIN FileSummaryInfo .Update Dim dlg As FileSummaryInfo GetCurValues dlg para$ = dlg.NumParas MsgBox &quot;There are &quot; + para$ + &quot; paragraphs in the document.&quot; End Sub To return the number of lines in a document:

  Sub MAIN FileSummaryInfo .Update Dim dlg As FileSummaryInfo GetCurValues dlg line$ = dlg.NumLines MsgBox &quot;There are &quot; + line$ + &quot; lines in the document.&quot; End Sub

Word version 2.x for Windows
To create a WordBasic macro that can be used to count the number of paragraphs or lines in a Word version 2.0 document and display the result in a message box, do the following:

From the Tools menu, choose Macro, and type a name, such as CountPara or CountLines, for the macro.

Click the Edit button.

Between Sub MAIN and End Sub, type the appropriate macro commands:


 * To count the paragraphs in a Word document:
 * To count the lines in a Word document:

From the File menu, choose Close, and save changes to the macro.