ControlCollection.AddBookmark Method (, String) (2007 System)
Adds a new Bookmark control to the document at the specified range.
Namespace: Microsoft.Office.Tools.Word
Assembly: Microsoft.Office.Tools.Word.v9.0 (in Microsoft.Office.Tools.Word.v9.0.dll)
Syntax
'Declaration
Public Function AddBookmark ( _
range As Range, _
name As String _
) As Bookmark
'Usage
Dim instance As ControlCollection
Dim range As Range
Dim name As String
Dim returnValue As Bookmark
returnValue = instance.AddBookmark(range, _
name)
public Bookmark AddBookmark(
Range range,
string name
)
public:
Bookmark^ AddBookmark(
Range^ range,
String^ name
)
public function AddBookmark(
range : Range,
name : String
) : Bookmark
Parameters
range
Type: RangeA Range that provides the bounds for the control.
name
Type: System.StringThe 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.
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
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.