共用方式為


Bookmark.Bookmarks Property

Definition

Gets a Bookmarks collection that represents all the bookmarks inside of the Bookmark control.

public:
 property Microsoft::Office::Interop::Word::Bookmarks ^ Bookmarks { Microsoft::Office::Interop::Word::Bookmarks ^ get(); };
public Microsoft.Office.Interop.Word.Bookmarks Bookmarks { get; }
member this.Bookmarks : Microsoft.Office.Interop.Word.Bookmarks
Public ReadOnly Property Bookmarks As Bookmarks

Property Value

A Bookmarks collection that represents all the bookmarks inside of the Bookmark control.

Examples

The following code example adds a Bookmark control with text to the document and then adds another bookmark to the sixth character of the bookmark. The total number of bookmarks found within the bookmark is then displayed in a message box.

This example is for a document-level customization.

private void BookmarkBookmarks()
{
    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.";
    bookmark1.Characters[6].Select();
    
    Microsoft.Office.Tools.Word.Bookmark bookmark2 =
        this.Controls.AddBookmark(Application.Selection.Range,
        "bookmark2");
    MessageBox.Show("Total Bookmarks in bookmark1: " +
        bookmark1.Bookmarks.Count);
}
Private Sub BookmarkBookmarks()

    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."
    Bookmark1.Characters(6).Select()

    Dim Bookmark2 As Microsoft.Office.Tools.Word.Bookmark = _
        Me.Controls.AddBookmark(Application.Selection.Range, _
        "Bookmark2")
    MessageBox.Show("Total Bookmarks in bookmark1: " _
        & Bookmark1.Bookmarks.Count.ToString)

End Sub

Remarks

It is not possible to enumerate each Bookmark control in the document using the Microsoft.Office.Interop.Word.Bookmarks collection. Use the ControlCollection and then look for items of type Bookmark.

Applies to