How many lines in a frame?

T

Thomas Winter

How can I count how many lines (not paragraphs) are in a Frame (not a
FrameSet, an old-fashioned Frame object)? Not sure if the Frame matters. I
would like to not have to change the Selection object. I've believe Word
2002 or 2003 has a new Lines collection. Has anyone tried this? I really
would like a solution that works on Word 97 on up. Thanks!

-Tom
 
W

Word Heretic

G'day "Thomas Winter" <[email protected]>,

range.information() has lots and lots of useful info you can use in
times like this


Thomas Winter said:
How can I count how many lines (not paragraphs) are in a Frame (not a
FrameSet, an old-fashioned Frame object)? Not sure if the Frame matters. I
would like to not have to change the Selection object. I've believe Word
2002 or 2003 has a new Lines collection. Has anyone tried this? I really
would like a solution that works on Word 97 on up. Thanks!

-Tom

Steve Hudson

Word Heretic, Sydney, Australia
Tricky stuff with Word or words for you.
wordheretic.com

If my answers r 2 terse, ask again or hassle an MVP,
at least they get recognition for it then.
Lengthy replies offlist require payment.
 
H

Helmut Weber

Hi Thomas,
unfortunately ...information(wdFirstCharacterLineNumber)
returns -1 in a textframe. So I see no way of counting
lines in a frame, but moving the selection to the
text in the frame, do the counting and return to the
previous position. Like that:
Sub LinesInFrame()
Dim p As Integer
Dim l As Integer
Dim r As Range
Set r = Selection.Range
l = 1
ActiveDocument.Shapes(1).TextFrame.TextRange.Select
' or whatever shape of type textframe
Selection.Collapse
p = Selection.start
Selection.MoveDown
While Selection.start <> p
l = l + 1
p = Selection.start
Selection.MoveDown
Wend
r.Select
MsgBox l
End Sub

Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, NT4.0
 
T

Thomas Winter

OK guys, tell me why this won't work:

oFrame.Range.ComputeStatistics(wdStatisticLines)

It works for me in Word 97 and Word 2003

I vaguelly recall some reason why this might NOT work though. Does anybody
have any warnings about this approach?

-Tom
 

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