다음을 통해 공유


Bookmark.Duplicate Property

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

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)

Syntax

'Declaration
ReadOnly Property Duplicate As Range
Range Duplicate { get; }

Property Value

Type: Microsoft.Office.Interop.Word.Range
A read-only Range object that represents all the properties of the Bookmark control.

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.

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 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
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");
    }
}

.NET Framework Security

See Also

Reference

Bookmark Interface

Microsoft.Office.Tools.Word Namespace