counting lines in a doc minus blank spaces

A

adykshoorn

I need to be able to count the lines typed in a document excluding blank lines. Word count currently counts all lines of all pages. I need this info for billing purposes. Is there any way to have Microsoft Word count just lines that have been typed?
 
H

Helmut Weber

Hi,
in case you are talking about empty
paragraphs (¶), the following might help:
---
Public Function EmptyPargraphs() As Long
Dim l As Long
l = 0
Dim oRng As Range
Set oRng = ActiveDocument.Range
Dim oPrg As Paragraph
For Each oPrg In oRng.Paragraphs
If oPrg.Range = Chr(13) Then
l = l + 1
End If
Next
EmptyPargraphs = l
End Function
 
J

Jezebel

Save the document. Then delete all blank lines and check the new line count.

To delete all blank lines:
1. Search for ^w^p and replace with ^p, to deal with lines that contain
white space but are otherwise empty.
2. Search for ^p^p and replace with ^p. Replace all and repeat until the
number found is zero.




adykshoorn said:
I need to be able to count the lines typed in a document excluding blank
lines. Word count currently counts all lines of all pages. I need this
info for billing purposes. Is there any way to have Microsoft Word count
just lines that have been typed?
 
H

Helmut Weber

Hi Jezebel,
except for an empty paragraph at the beginning of the doc and
except for two empty paragraphs at the end of doc, at last.
In that case replacing ^p^p by ^p would need considerable time.
;-)
I'd suggest, that MS would revive the end of doc mark.
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 
H

Helmut Weber

Hi Jezebel,
Search for ^p^p and replace with ^p.
Replace all and repeat until the
number found is zero.
in case of two empty paragraphs at the doc end,
the number found will never be zero.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
 
J

Jezebel

It hadn't occurred to me that you might try counting the lines of an empty
document. I guess we have different conceptions of useful activity.
 
H

Helmut Weber

Sorry Jezebel,
Your knowledge and reputation are quite remarkable.
I should have been more accurate. My restriction is about
the last paragraph in a doc, in case it is empty!
:)
Then replacing ^p^p by ^p until found equals zero results in an
endless loop in all version of word I know, no matter how much text
the doc contains, of course. We just had a lenthy discussion on this
in public.de.word.vba, where Klaus Linke, MVP, and Christian
Fressdorf, MVP, were involved. The result was that the last paragraph,
if empty, resists all such attacks. See "macro hangs up on last para
return" by Steven Drenker. Even Jay Freedman's and all similar
replacing attempts, I came acrosss so far, don't get rid of it.
 

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