Compartir a través de


ControlCollection.AddBookmark Method

Definition

Overloads

AddBookmark(Bookmark, String)

Adds a new Bookmark control to the document at the location of the existing Bookmark specified.

AddBookmark(Range, String)

Adds a new Bookmark control to the document at the specified range.

AddBookmark(Bookmark, String)

Adds a new Bookmark control to the document at the location of the existing Bookmark specified.

public:
 Microsoft::Office::Tools::Word::Bookmark ^ AddBookmark(Microsoft::Office::Interop::Word::Bookmark ^ bookmark, System::String ^ name);
public Microsoft.Office.Tools.Word.Bookmark AddBookmark (Microsoft.Office.Interop.Word.Bookmark bookmark, string name);
abstract member AddBookmark : Microsoft.Office.Interop.Word.Bookmark * string -> Microsoft.Office.Tools.Word.Bookmark
Public Function AddBookmark (bookmark As Bookmark, name As String) As Bookmark

Parameters

bookmark
Bookmark

The existing Bookmark that you want to replace with a new Bookmark control.

name
String

The name that can be used to index the control in the ControlCollection instance.

Returns

The Bookmark control that was added to the ControlCollection instance.

Applies to

AddBookmark(Range, String)

Adds a new Bookmark control to the document at the specified range.

public:
 Microsoft::Office::Tools::Word::Bookmark ^ AddBookmark(Microsoft::Office::Interop::Word::Range ^ range, System::String ^ name);
public Microsoft.Office.Tools.Word.Bookmark AddBookmark (Microsoft.Office.Interop.Word.Range range, string name);
abstract member AddBookmark : Microsoft.Office.Interop.Word.Range * string -> Microsoft.Office.Tools.Word.Bookmark
Public Function AddBookmark (range As Range, name As String) As Bookmark

Parameters

range
Range

A Range that provides the bounds for the control.

name
String

The name that can be used to index the control in the ControlCollection instance.

Returns

The Bookmark control that was added to the ControlCollection instance.

Exceptions

The name or range argument is null, or the name argument has zero length.

A control with the same name is already in the ControlCollection instance.

The range that was specified is not valid.

Examples

The following code example adds a Bookmark control to the document, and then adds text to the bookmark.

private void WordAddBookmark()
{
    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.";
}
Private Sub WordAddBookmark()
    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."
End Sub

Remarks

This method enables you to add Bookmark controls to the end of the ControlCollection.

To remove a Bookmark control that was added programmatically, use the Remove method.

Applies to