Bookmark.InRange Method
Determines if the Range to which the method is applied is contained in the Bookmark control.
Namespace: Microsoft.Office.Tools.Word
Assembly: Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)
Syntax
'Declaration
Function InRange ( _
Range As Range _
) As Boolean
bool InRange(
Range Range
)
Parameters
Range
Type: Microsoft.Office.Interop.Word.RangeRange object.
Return Value
Type: System.Boolean
true if the Range specified is within the Bookmark control to which the method is applied; otherwise, false.
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.
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 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
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.");
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.