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

Last reviewed: July 30, 1997
Article ID: 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 95, versions 7.0, 7.0a
  • 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 "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.

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 "There are " + para$ + " paragraphs in the document."
   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 "There are " + line$ + " lines in the document."
   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:

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

  2. Click the Edit button.

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

        - To count the paragraphs in a Word document:
    

             StartOfDocument
             While ParaDown()
             count = count + 1
             Wend
             MsgBox "There are" + Str$(count) + " paragraphs in the document."
    
        - To count the lines in a Word document:
    
             StartOfDocument
             While LineDown()
             count = count + 1
             Wend
             MsgBox "There are" + Str$(count) + " lines in the document."
    
    

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

REFERENCES

"Microsoft Word for Windows and OS/2 Technical Reference," pages 103-

 107
"Using WordBasic," by WexTech Systems and Microsoft, pages 251 and 267


Additional query words: LineDown ParaDown While
Version : 2.x 6.x 7.0 7.0a | 6.0 6.


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.