
detecting hard carriage return's on line counting macro
Thanks :)
I see what the macro does by running it, and knowing that helps me to figure
out why it works by looking at the code (I don't know VBA for Word at all,
but I know VBA for excel so i can puzzle through it). Looks like I need to
look into how Selection.Find works...
I have a fair amount of work to do to polish this thing up. For instance, I
was trying to reconcile my line count with Word's (I haven't been able find
any documentation on how they calculate their lines) and I figured out that
they count a page break as a line. (The page break thing really throws
everything off as the blank line after is counted as blank either by the
macro).
I can go from here I think (just need to delve a little deeper), you've both
given me a great place to start from.
Thanks again!
Quote:
> Hi,
> Mike,
> Use the following:
> Dim para As Paragraph, iCount As Integer
> iCount = 0
> ActiveDocument.UndoClear
> Selection.Find.ClearFormatting
> Selection.Find.Replacement.ClearFormatting
> With Selection.Find
> .Forward = True
> .Wrap = wdFindContinue
> .Format = False
> .MatchCase = False
> .MatchWholeWord = False
> .MatchWildcards = False
> .MatchSoundsLike = False
> .MatchAllWordForms = False
> Do While .Execute(FindText:="^l^p", Wrap:=wdFindContinue,
> Forward:=True, ReplaceWith:="") = True
> iCount = iCount + 1
> Loop
> End With
> For Each para In ActiveDocument.Paragraphs
> If para.Range = vbCr Then
> iCount = iCount + 1
> para.Range.Delete
> End If
> Next para
> MsgBox "There are " &
> ActiveDocument.BuiltInDocumentProperties(wdPropertyLines) & " non-blank
> lines in the document."
> ActiveDocument.Undo (iCount)
> Please post any response to the newsgroups for the benefit of others who
may
> also be following the thread.
> Hope this helps,
> Doug Robbins - Word MVP
> > I'm trying to develope a macro that will count lines but skip blank
lines.
> > The macro below was suggested to me by Martin, and works with one
> exception,
> > it doesn't allow for hard carriage returns (vbVerticalTab contant),
input
> > with shift-enter.
> > If there are, say 4 vertical tabs and then a paragraph marker, that's 5
> > blank lines the macro wouldn't pick up (it wouldn't pick up the
follow-up
> > paragraph marker as blank because it contains something other than just
> > itself, i.e. the hard carriage returns).
> > can someone tell me how I can loop through the paragraph counting hard
> > carriage returns on lines by themselves? And then I would also need to
> > count the final paragraph marker, but only if it followed directly
behind
> a
> > hard carriage return (thus representing an additional blank line).
> > ----Martin's macro:
> > Hi Mike
> > You could count the 'empty' lines and subract them from teh total number
> > of lines ... like this:
> > '-----
> > Sub CountLines()
> > Dim para As Paragraph
> > Dim iCount As Long
> > iCount = 0
> > For Each para In ActiveDocument.Paragraphs
> > If para.Range = vbCr Then
> > iCount = iCount + 1
> > End If
> > Next para
> > MsgBox Str(ActiveDocument.BuiltInDocumentProperties(wdPropertyLines) -
> > iCount)
> > End Sub