InStory Method

Microsoft Word Visual Basic

Show All

InStory Method

       

True if the selection or range to which this method is applied is in the same story as the range specified by the Range argument.

Note   A range can belong to only one story.

expression.InStory(Range)

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

Range   Required Range object. The Range object whose story is compared with the story that contains expression.

Example

This example determines whether the selection is in the same story as the first paragraph in the active document. The message box displays "False" because the selection is in the primary header story and the first paragraph is in the main text story.

With ActiveDocument.ActiveWindow.View
    .Type = wdPrintView
    .SeekView = wdSeekCurrentPageHeader
End With
same = Selection.InStory(ActiveDocument.Paragraphs(1).Range)
MsgBox same

This example determines whether Range1 and Range2 are in the same story. If they are, bold formatting is applied to Range1.

Set Range1 = Selection.Words(1)
Set Range2 = ActiveDocument.Range(Start:=20, End:=100)
If Range1.InStory(Range:=Range2) = True Then
    Range1.Font.Bold = True
End If