ControlCollection.AddBookmark Method (Range, String)

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

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

Syntax

'Declaration
Function AddBookmark ( _
    range As Range, _
    name As String _
) As Bookmark
Bookmark AddBookmark(
    Range range,
    string name
)

Parameters

  • range
    Type: Range

    A Range that provides the bounds for the control.

Return Value

Type: Microsoft.Office.Tools.Word.Bookmark
The Bookmark control that was added to the ControlCollection instance.

Exceptions

Exception Condition
ArgumentNullException

The name or range argument is nulla null reference (Nothing in Visual Basic), or the name argument has zero length.

ControlNameAlreadyExistsException

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

InvalidRangeException

The range that was specified is not valid.

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.

Examples

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

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

.NET Framework Security

See Also

Reference

ControlCollection Interface

AddBookmark Overload

Microsoft.Office.Tools.Word Namespace