Share via


Bookmarks Collection Object

Word Developer Reference

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

Remarks

Use the Bookmarks property to return the Bookmarks collection for a document, range, or selection. The following example ensures that the bookmark named "temp" exists in the active document before selecting the bookmark.

Visual Basic for Applications
  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".

Visual Basic for Applications
  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.

Visual Basic for Applications
  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 alphabetical 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.

Visual Basic for Applications
  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.

See Also