John Rodgers said:
Is it possible with the Word object model to determine
what text is visible onscreen at any particular time?
Hi John,
Not easily, as far as I can see. The code below doesn't work too well: It's off by a few lines, and doesn't perfectly catch what's visible of those lines. Maybe I have made an error you can correct, or maybe ..RangeFromPoint is a bit buggy.
Greetings,
Klaus
Dim pLeft As Long
Dim pTop As Long
Dim pWidth As Long
Dim pHeight As Long
Dim rngStart As Range, rngEnd As Range
Dim myDoc As Document
Set myDoc = ActiveDocument
With myDoc.ActiveWindow
pLeft = PointsToPixels(.Left)
pTop = PointsToPixels(.Top)
pWidth = PointsToPixels(.Width)
pHeight = PointsToPixels(.Height)
Set rngStart = .RangeFromPoint(pLeft, pTop)
Set rngEnd = .RangeFromPoint(pLeft + pWidth, pTop)
rngStart.End = rngEnd.End
MsgBox rngStart.Text, , "First line"
Set rngStart = .RangeFromPoint(pLeft, pTop + pHeight)
Set rngEnd = .RangeFromPoint(pLeft + pWidth, pTop + pHeight)
rngStart.End = rngEnd.End
MsgBox rngStart.Text, , "Last line"
End With