Word VBA, Bookmarks
In this article I will explain the basics of working with bookmarks in VBA for word.
Bookmarks can be created by using the Add method of the Bookmarks collection:
The input parameter to the Add method is a text string to name the bookmark.
The bookmark will be created at the location of the cursor at the time of calling the function.
Note: The Add method of the Bookmarks collection also accepts a second optional parameter. A range object. If passed the bookmark will be created at the start location of the range object rather than the current cursor location.
The code below creates a bookmark at the second line of the document. This is independant of the current position of the cursor:
Bookmarks can be deleted using any of the methods below:
Method 1: Using the bookmark index. Bookmarks are indexed starting from the number 1:
Method 2: Using the bookmark name:
Method 3: Using a bookmark object:
Check if Bookmark Exists:
You can download the file and code related to this article from the link below: