Bookmark.Copy Method

Definition

Creates a new Bookmark object in the same location as the existing Bookmark control.

Overloads

Copy()

Creates a new Bookmark in the same location as the existing Bookmark control.

Copy(String)

Creates a new Bookmark with the specified Name argument in the same location as the existing Bookmark control.

Remarks

The new bookmark is a Microsoft.Office.Interop.Word.Bookmark object rather than a Microsoft.Office.Tools.Word.Bookmark control.

Copy()

Creates a new Bookmark in the same location as the existing Bookmark control.

public:
 void Copy();
public void Copy ();
abstract member Copy : unit -> unit
Public Sub Copy ()

Examples

The following code example adds a Bookmark control to the document and then creates a BeforeRightClick event handler. When the Bookmark control is right-clicked, the text within the bookmark is copied to the Clipboard.

This example is for a document-level customization.

Microsoft.Office.Tools.Word.Bookmark bookmark3;

private void BookmarkBeforeRightClick()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    bookmark3 = this.Controls.AddBookmark(this.Paragraphs[1]
        .Range, "bookmark3");
    bookmark3.Text = "This is a sample bookmark.";
    bookmark3.BeforeRightClick += new Microsoft.Office.Tools
        .Word.ClickEventHandler(bookmark3_BeforeRightClick);
}

void bookmark3_BeforeRightClick(object sender, 
    Microsoft.Office.Tools.Word.ClickEventArgs e)
{
    bookmark3.Copy();
    e.Cancel = true;
}
WithEvents Bookmark3 As Microsoft.Office.Tools.Word.Bookmark

Private Sub BookmarkBeforeRightClick()
    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Bookmark3 = Me.Controls.AddBookmark(Me.Paragraphs(1).Range, "Bookmark3")
    Bookmark3.Text = "This is a sample bookmark."
End Sub

Private Sub Bookmark3_BeforeRightClick(ByVal sender As Object, _
    ByVal e As Microsoft.Office.Tools.Word.ClickEventArgs) _
    Handles Bookmark3.BeforeRightClick
    Bookmark3.Copy()
    e.Cancel = True
End Sub

Remarks

The new bookmark is a Microsoft.Office.Interop.Word.Bookmark object rather than a Microsoft.Office.Tools.Word.Bookmark control.

Applies to

Copy(String)

Creates a new Bookmark with the specified Name argument in the same location as the existing Bookmark control.

public:
 Microsoft::Office::Interop::Word::Bookmark ^ Copy(System::String ^ Name);
public Microsoft.Office.Interop.Word.Bookmark Copy (string Name);
abstract member Copy : string -> Microsoft.Office.Interop.Word.Bookmark
Public Function Copy (Name As String) As Bookmark

Parameters

Name
String

The name of the new bookmark.

Returns

A Bookmark object.

Examples

The following code example adds a Bookmark control with text to the first paragraph, then copies the bookmark to the same location as the original bookmark. A message box displays the type and location of each bookmark.

This example is for a document-level customization.

private void BookmarkCopy()
{
    this.Paragraphs[1].Range.InsertParagraphBefore();
    Microsoft.Office.Tools.Word.Bookmark bookmark1 =
        this.Controls.AddBookmark(this.Paragraphs[1].Range,
        "bookmark1");
    bookmark1.Text = "bookmark1";

    Word.Bookmark bookmark2 = bookmark1.Copy("bookmark2");

    MessageBox.Show("The range of bookmark1 starts at " + 
        bookmark1.Range.Start.ToString() + " and ends at " + 
        bookmark1.Range.End.ToString() + ".\n\n" + "The range " +
        "of bookmark2 starts at " + bookmark2.Range.Start.ToString()
        + " and ends at " + bookmark2.Range.End.ToString() + ".");
}
Private Sub BookmarkCopy()

    Me.Paragraphs(1).Range.InsertParagraphBefore()
    Dim Bookmark1 As Microsoft.Office.Tools.Word.Bookmark = _
        Me.Controls.AddBookmark(Me.Paragraphs(1).Range, "Bookmark1")
    Bookmark1.Text = "Bookmark1"

    Dim Bookmark2 As Word.Bookmark = Bookmark1.Copy("Bookmark2")

    MessageBox.Show("The range of Bookmark1 starts at " & _
        Bookmark1.Range.Start.ToString & " and ends at " & _
        Bookmark1.Range.End.ToString & "." & vbLf & "The range " & _
        "of Bookmark2 starts at " & Bookmark2.Range.Start.ToString & _
        " and ends at " & Bookmark2.Range.End.ToString & ".")

End Sub

Remarks

The new bookmark is a Microsoft.Office.Interop.Word.Bookmark object rather than a Microsoft.Office.Tools.Word.Bookmark control.

Applies to