Share via


Bookmark.InStory(Range) Method

Definition

Determines if the Bookmark control to which this method is applied is in the same story as the range specified by the Range argument.

public:
 bool InStory(Microsoft::Office::Interop::Word::Range ^ Range);
public bool InStory (Microsoft.Office.Interop.Word.Range Range);
abstract member InStory : Microsoft.Office.Interop.Word.Range -> bool
Public Function InStory (Range As Range) As Boolean

Parameters

Range
Range

The Range object whose story is compared with the story that contains the Bookmark control.

Returns

true if the Bookmark control to which this method is applied is in the same story as the range specified by the Range argument; otherwise, false.

Examples

The following code example adds a Bookmark control with text to the document and then checks to find out whether or not it is in the same story as the first paragraph. The results are then displayed in a message box.

This example is for a document-level customization.

private void BookmarkInStory()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Bookmark bookmark1 =
        this.Controls.AddBookmark(this.Paragraphs[1].Range,
        "bookmark1");
    bookmark1.Text = "This is sample bookmark text.";
    
    if (bookmark1.InStory(this.Paragraphs[1].Range))
    {
        MessageBox.Show("The bookmark is in the same story as "+
            "the first paragraph.");
    }
    else
    {
        MessageBox.Show("The bookmark is not in the same story " +
            "as the first paragraph.");
    }
}
Private Sub BookmarkInStory()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Dim Bookmark1 As Microsoft.Office.Tools.Word.Bookmark = _
        Me.Controls.AddBookmark(Me.Paragraphs(1).Range, "Bookmark1")
    Bookmark1.Text = "This is sample bookmark text."

    If Bookmark1.InStory(Me.Paragraphs(1).Range) Then
        MessageBox.Show("The bookmark is in the same story as " _
            & "the first paragraph.")
    Else
        MessageBox.Show("The bookmark is not in the same story " _
            & "as the first paragraph.")
    End If

End Sub

Applies to