次の方法で共有


Bookmark.BookmarkID Property

Gets the position of the Bookmark control in the document.

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

Syntax

'Declaration
ReadOnly Property BookmarkID As Integer
int BookmarkID { get; }

Property Value

Type: System.Int32
The position of the Bookmark control in the document.

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.

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 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
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);
}

.NET Framework Security

See Also

Reference

Bookmark Interface

Microsoft.Office.Tools.Word Namespace