How to find out whether a range is off-screen

Article contributed by Jonathan West

If the [Range].Information(wdHorizontalPositionRelativeToPage) property returns -1, then the range is not on screen. However if part of the range is on screen, it will not return -1. So if you want to check specifically whether the start or end of the range is on screen, you would need to collapse the range:

Sub CheckIfEndOfRangeOnScreen()

    Dim MyRange As Range, EndOfRange As Range
    Set MyRange = ActiveDocument.Range
    Set EndOfRange = MyRange.Duplicate
    EndOfRange.Collapse wdCollapseEnd
    If EndOfRange.Information(wdHorizontalPositionRelativeToPage) = -1 Then
        MsgBox "The end of the range is not on screen"
    End If

End Sub

Click to view Terms of Use page

Click to view Disclaimer page