Hi Jonas,
one method:
Sub LinesInCell()
Dim z1 As Integer
Dim z2 As Integer
With Selection
.Cells(1).Select
z1 = .Information(wdFirstCharacterLineNumber)
.EndKey
z2 = .Information(wdFirstCharacterLineNumber)
End With
MsgBox z2 - z1 + 1
End Sub
But not reliable anymore, as in Word 2002
unlike in Word 97 all too often
..Information(wdFirstCharacterLineNumber) returns -1,
and as this does not provide for cells reaching over
page breaks.
Another method:
Sub LinesInCell_1()
Dim r As Long
Dim l As Long
With Selection
.Cells(1).Select
.Collapse
l = 0
r = .Cells(1).RowIndex
On Error Resume Next
Do Until r <> .Cells(1).RowIndex
If Err.Number = 5941 Then
Err.Clear
Exit Do
End If
l = l + 1
.MoveDown
Loop
.MoveUp ' or better restore original selection
End With
MsgBox l
End Sub
Counts lines even if the cell spans over several pages.
You might add some lines to get the selection back
to where it was before doing the counting.
And better rewrite it to a function.
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000