HOw to count number of lines in a HEADER?

K

khalid

Hello all,

I am trying to figure out the syntax for counting the number of lines a
range of text in the HEADER spans. I am able to easily do this for text that
is not in the header (by finding the beginning line of where it starts and
where it ends and subtracting the 2).

I use this code for finding the line starts:

Range.Information(wdFirstCharacterLineNumber)

This will find the line starts, but the problem is it always returns -1 when
the range is in the header (or footer for that matter). Is there another way
I can find how many lines a range wraps in the header?

Pulling my hair trying to figure this one....

Thanks in advance!!!
 
H

Helmut Weber

Hi khalid,

four years ago I posted that,
and nobody came up with a better solution,
at least, Google doesn't show it.

Sub test2()
Dim i As Integer
i = 1
ActiveDocument.StoryRanges(wdPrimaryHeaderStory).Select
Selection.Collapse Direction:=wdCollapseEnd
While Selection.Range.Start <> 0
i = i + 1
Selection.HomeKey unit:=wdLine
Selection.MoveUp
Wend
MsgBox i ' number of lines
ActiveWindow.ActivePane.Close
ActiveDocument.Range(0, 0).Select ' if you like
End Sub

For theory, I don't use integers no longer, but longs.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
T

Tony Jollans

You can use something along these lines anywhere in a document as far as I
know - no need for anything more complicated ....

Msgbox
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.ComputeStati
stics(wdStatisticLines)
 
H

Helmut Weber

Hi Tony,

yes. :)

I should have known that.

Did you read the posting about creating
1000 templates from 1000 jpegs?

So far so good.
The watermark is there.

But when trying to add text to the header,
I get nothing but spaces.

???

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
K

khalid

Tony,

Thanks a lot - I was exactly looking for just that!

Helmut thanks for your solution too.
 

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