Re: Determine visible text on screen by John
John
Tue May 10 12:13:38 CDT 2005
Klaus Linke wrote:
> "John Rodgers" <john@eco-online.com> wrote:
>
>>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
>
Thanks Klaus,
I'll give it a try later today - I totally missed the PointsToPixels /
RangeFromPoint when searching thru the documentation (guess my eyes must
have glazed over...)
Thanks,
John