共用方式為


Bookmark.InRange(Range) Method

Definition

Determines if the Range to which the method is applied is contained in the Bookmark control.

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

Parameters

Range
Range

Range object.

Returns

true if the Range specified is within the Bookmark control to which the method is applied; otherwise, false.

Examples

The following code example adds a Bookmark control with text to the document and then checks to determine whether or not the bookmark is in the same range as Paragraph 1. This code then displays the results in a message box.

This example is for a document-level customization.

private void BookmarkInRange()
{
    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.InRange(this.Paragraphs[1].Range))
    {
        MessageBox.Show("The bookmark is in the first paragraph.");
    }
    else
    {
        MessageBox.Show("The bookmark is not in the first paragraph.");
    }
}
Private Sub BookmarkInRange()

    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.InRange(Me.Paragraphs(1).Range) Then
        MessageBox.Show("The bookmark is in the first paragraph.")
    Else
        MessageBox.Show("The bookmark is not in the first paragraph.")
    End If

End Sub

Remarks

This method determines whether the Range is contained in the Bookmark control by comparing the starting and ending character positions, as well as the story type.

Applies to