Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
AddBookmark Method (Range, String)
Collapse the table of content
Expand the table of content

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)

Bookmark AddBookmark(
	Range range,
	string name
)

Parameters

range
Type: Microsoft.Office.Interop.Word.Range

A Range that provides the bounds for the control.

name
Type: System.String

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

Return Value

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

ExceptionCondition
ArgumentNullException

The name or range argument is null, 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.

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.

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

Show:
© 2015 Microsoft