WD: Macros to Count the Number of Document Paragraphs and Lines
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
-
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 "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:
- 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:
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."
- 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
Keywords :
Version : MACINTOSH:6.0,6.0.1,6.0.1a; WINDOWS:2.0,2.0a,2.0a-CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0,7.0a
Platform : MACINTOSH WINDOWS
Issue type :