count lines and chars

D

DavidC

How do i retrieve the same statistics under tools >> word count..

I know i can get words & paragraphs,

BUT HOW DO I get lines, pages, characters (spaces) and characters (no
spaces)???????



i knocked up a little program retrieving words, chars and paragraphs and the
numbers did not match what the document actually had on those
statistics?!?!?!?
 
P

Peter Hewett

Hi DavidC

Try the following code:

Public Sub Statistics()
Dim tblItem As Word.Table
Dim rngReplace As Word.Range
Dim rngFound As Word.Range
Dim lngCharacters As Long
Dim lngCharactersWithSpaces As Long
Dim lngFarEastCharacters As Long
Dim lngLines As Long
Dim lngPages As Long
Dim lngParagraphs As Long
Dim lngWords As Long

' Get the totals for the document
With ActiveDocument
lngCharacters = .ComputeStatistics(wdStatisticCharacters)
lngCharactersWithSpaces = _
.ComputeStatistics(wdStatisticCharactersWithSpaces)
lngFarEastCharacters = _
.ComputeStatistics(wdStatisticFarEastCharacters)
lngLines = .ComputeStatistics(wdStatisticLines)
lngPages = .ComputeStatistics(wdStatisticPages)
lngParagraphs = .ComputeStatistics(wdStatisticParagraphs)
lngWords = .ComputeStatistics(wdStatisticWords)
End With

MsgBox "Pages: " & lngPages & vbCr & _
"Paragraphs: " & lngParagraphs & vbCr & _
"Lines: " & lngLines & vbCr & _
"Words: " & lngWords & vbCr & _
"Characters: " & lngCharacters & vbCr & _
"Characters with spaces: " & lngCharactersWithSpaces & vbCr & _
"Far east Characters: " & lngFarEastCharacters
End Sub

HTH + Cheers - Peter
 
D

Dong Ge

Hi! DavidC,

I have post same question last night, and I found a way to gel line
counts today. Maybe it' not better, but it can run without error.

'Get the number of all lines of the document.
Selection.EndKey (wdStory)
numLines = Selection.Information(wdFirstCharacterLineNumber) + _
(Selection.Information(wdActiveEndPageNumber) - 1) *
100
numBlocks = 18

'Cut the beginning 18 lines to the clipboard.
Selection.HomeKey (wdStory)
Selection.MoveEnd wdLine, 18
Selection.Cut
 

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