Share via


Bookmark.BookmarkID Property

Definition

Gets the position of the Bookmark control in the document.

public:
 property int BookmarkID { int get(); };
public int BookmarkID { get; }
member this.BookmarkID : int
Public ReadOnly Property BookmarkID As Integer

Property Value

The position of the Bookmark control in the document.

Examples

The following code example adds a Bookmark control to the document and then displays the position of the bookmark in the document by showing the BookmarkID in a message box.

This example is for a document-level customization.

private void BookmarkBookmarkID()
{
    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.";
    MessageBox.Show("Bookmark position in document: " 
        + bookmark1.BookmarkID);
}
Private Sub BookmarkBookmarkID()

    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."
    MessageBox.Show("Bookmark position in document: " _
        & Bookmark1.BookmarkID.ToString)

End Sub

Remarks

The number corresponds to the order of the Bookmark control in the document: 1 for the first bookmark, 2 for the second one, and so on. If one of the bookmarks is deleted, then the BookmarkID of the other bookmarks will renumber accordingly.

Applies to