InRange Method

Returns True if the range or selection to which the method is applied is contained in the range specified by the Range argument.


expression Required. An expression that returns a Range or Selection object.

Range    Required Range object. The range to which you want to compare expression.


This method determines whether the range or selection returned by expression is contained in the specified Range by comparing the starting and ending character positions, as well as the story type.


This example determines whether the selection is contained in the first paragraph in the active document.

status = Selection.InRange(ActiveDocument.Paragraphs(1).Range)

This example sets myRange equal to the first word in the active document. If myRange isn't contained in the selection, myRange is selected.

Set myRange = ActiveDocument.Words(1)
If myRange.InRange(Selection.Range) = False Then myRange.Select

This example displays a message if the selection is in the footnote story.

If Selection.InRange(ActiveDocument _
        .StoryRanges(wdFootnotesStory)) Then
    MsgBox "Selection in footnotes"
End If

Applies to | Range Object | Selection Object

See Also | End Property | InStory Method | IsEqual Method | Start Property | StoryType Property