Bookmarks Collection Object

Microsoft Word Visual Basic

Bookmarks Collection Object

         
Multiple objects Bookmarks (Bookmark)
Range

A collection of Bookmark objects that represent the bookmarks in the specified selection, range, or document.

Using the Bookmarks Collection

Use the Bookmarks property to return the Bookmarks collection. The following example ensures that the bookmark named "temp" exists in the active document before selecting the bookmark.

If ActiveDocument.Bookmarks.Exists("temp") = True Then
    ActiveDocument.Bookmarks("temp").Select
End If

Use the Add method to set a bookmark for a range in a document. The following example marks the selection by adding a bookmark named "temp".

ActiveDocument.Bookmarks.Add Name:="temp", Range:=Selection.Range

Use Bookmarks(index), where index is the bookmark name or index number, to return a single Bookmark object. You must exactly match the spelling (but not necessarily the capitalization) of the bookmark name. The following example selects the bookmark named "temp" in the active document.

ActiveDocument.Bookmarks("temp").Select

The index number represents the position of the bookmark in the Selection or Range object. For the Document object, the index number represents the position of the bookmark in the alphabetic list of bookmarks in the Bookmarks dialog box (click Name to sort the list of bookmarks alphabetically). The following example displays the name of the second bookmark in the Bookmarks collection.

MsgBox ActiveDocument.Bookmarks(2).Name

Remarks

The ShowHidden property effects the number of elements in the Bookmarks collection. If ShowHidden is True, hidden bookmarks are included in the Bookmarks collection.