다음을 통해 공유


Bookmark.Duplicate Property

Definition

Gets a read-only Range object that represents all the properties of the Bookmark control.

public:
 property Microsoft::Office::Interop::Word::Range ^ Duplicate { Microsoft::Office::Interop::Word::Range ^ get(); };
public Microsoft.Office.Interop.Word.Range Duplicate { get; }
member this.Duplicate : Microsoft.Office.Interop.Word.Range
Public ReadOnly Property Duplicate As Range

Property Value

A read-only Range object that represents all the properties of the Bookmark control.

Examples

The following code example adds a Bookmark control with text to the first paragraph and sets the text to bold. It then returns a range from the Duplicate property of the Bookmark and displays a message box indicating that the range contains the same properties as the bookmark.

This example is for a document-level customization.

private void BookmarkDuplicate()
{
    int WordTrue = 1;
    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.";
    bookmark1.Bold = WordTrue;
                
    Word.Range myRange = bookmark1.Duplicate;
    if (myRange.Font.Bold == WordTrue)
    {
        MessageBox.Show("MyRange is bold because Bookmark1 has"
            + " its Bold property set to true");
    }
    else
    {
        MessageBox.Show("MyRange is not bold because Bookmark1 has"
            + " its Bold property set to false");
    }
}
Private Sub BookmarkDuplicate()

    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."
    Bookmark1.Bold = True

    Dim myRange As Word.Range = Bookmark1.Duplicate
    If myRange.Font.Bold = True Then
        MessageBox.Show("MyRange is bold because Bookmark1 has" & _
            " its Bold property set to True")
    Else
        MessageBox.Show("MyRange is not bold because Bookmark1 has" & _
            " its Bold property set to False")
    End If

End Sub

Remarks

You can assign the object returned by the Duplicate property to another Range to apply those settings all at once. Before assigning the duplicate object to another Range, you can change any of the properties of the duplicate object without affecting the original.

By duplicating a Range object, you can change the starting or ending character position of the duplicate range without changing the original range.

Applies to