Article ID: 181442
Article Last Modified on 6/17/2005
Sub LinesAndParagraphsCount()
Dim AD As Document
Dim DP As Object
Set AD = ActiveDocument
Set DP = AD.BuiltInDocumentProperties
' Method 1 - Returns the number of paragraphs in a document.
MsgBox "There are " & AD.Paragraphs.Count & " paragraphs."
' Method 2 - Returns the number of paragraphs and lines in a
' document.
MsgBox "There are " & DP("Number Of Paragraphs") & " paragraphs."
MsgBox "There are " & DP("Number Of Lines") & " lines."
' Method 3 - Returns the number of selected paragraphs and lines
' in a document.
nParas = Selection.Paragraphs.Count
nLines = Selection.Range. _
ComputeStatistics(Statistic:=wdStatisticLines)
MsgBox "The selection contains " & nParas & " paragraphs."
MsgBox "The selection contains " & nLines & " lines."
End Sub
For additional information, please see the following article in the
Microsoft Knowledge Base:
173707 OFF97: How to Run Sample Code from Knowledge Base Articles
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: wordcon
Keywords: kbhowto kbdtacode KB181442