How to get linecount for each page in a word document

U

upendra

Hi,

I would like to know the last line number in each and every page in a
given word document.

Example: Page 1- 39 Lines,Page2-47 Lines etc.,

I have tried the below but the resultant no.of lines information is
not correct by this method.

Sub linecount()
For i = 1 To ActiveWindow.Panes.Item(1).Pages.Count
Debug.Print "Page" & i & "–" &
ActiveWindow.Panes.Item(1).Pages(i).Rectangles.Item(1).Lines.Count & "
Lines", vbOKOnly, "Pagewise Line Count"
Next

End Sub

As there is now page.lines count sort of VBA command in Word. Kindly
help me if anybody knows how to achieve this.
 
S

StevenM

To: Upendra,

Sub LinesPerPage()
Dim nPage As Long
Dim nLines As Long
Dim sStr As String

For nPage = 1 To Selection.Information(wdNumberOfPagesInDocument)
Selection.GoTo What:=wdGoToPage, Name:=nPage
Selection.Bookmarks("\page").Range.Select
nLines = Selection.Range.ComputeStatistics(wdStatisticLines)
sStr = sStr & "Page: " & nPage & " = " & nLines & " lines." & vbCr
Next nPage
MsgBox sStr
End Sub

Steven Craig Miller
 
M

macropod

Hi upendra,

Try:
Sub PagewiseLineCount()
Dim i As Integer
Dim MyRange As Range
With ActiveDocument
Set MyRange = .Range(0, 0)
For i = 1 To ActiveDocument.ComputeStatistics(wdStatisticPages)
Set MyRange = MyRange.GoTo(What:=wdGoToPage, Name:=i)
Set MyRange = MyRange.GoTo(What:=wdGoToBookmark, Name:="\page")
MsgBox "Page " & i & " – " & _
MyRange.ComputeStatistics(wdStatisticLines) & _
" Lines ", vbOKOnly, " Pagewise Line Count"
Next
End With
End Sub

--
Cheers
macropod
[MVP - Microsoft Word]


Hi,

I would like to know the last line number in each and every page in a
given word document.

Example: Page 1- 39 Lines,Page2-47 Lines etc.,

I have tried the below but the resultant no.of lines information is
not correct by this method.

Sub linecount()
For i = 1 To ActiveWindow.Panes.Item(1).Pages.Count
Debug.Print "Page" & i & "–" &
ActiveWindow.Panes.Item(1).Pages(i).Rectangles.Item(1).Lines.Count & "
Lines", vbOKOnly, "Pagewise Line Count"
Next

End Sub

As there is now page.lines count sort of VBA command in Word. Kindly
help me if anybody knows how to achieve this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top