Please Note: This article is written for users of the following Microsoft Word versions: 97, 2000, 2002, and 2003. If you are using a later version (Word 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Word, click here: Selecting a Bookmark in a Macro.

Selecting a Bookmark in a Macro

by Allen Wyatt
(last updated December 14, 2015)

2

You can select the text or document location referenced by a bookmark very easily with a macro. For instance, let's say you had a bookmark named MyBkMark, and you wanted to select the text it represents. The following code fragment will do the trick:

ActiveDocument.Bookmarks("MyBkMark").Select

You should note that the above will only work if you know the name of the bookmark. If you don't know a particular bookmark's name, you can use an index offset instead, as follows:

ActiveDocument.Bookmarks(3).Select

When this code line is executed, the bookmark represented by index 3 is selected, regardless of the name. Another alternative, of course, is to retrieve the name of the defined bookmarks and then use them within your code.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (799) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Selecting a Bookmark in a Macro.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Documenting Changes in VBA Code

Your company may be regulated by requirements that it document any changes to the macros in an Excel worksheet. Your options ...

Discover More

Making Spell Check Ignore Characters

The rules of professional editing often require that editorial changes in a quote be noted with brackets. These brackets, ...

Discover More

Links to Hyperlinks

Hyperlinks in a worksheet can be helpful or essential, depending on the nature of your data. If you create a link to a ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

MORE WORDTIPS (MENU)

Counting Characters in a Selection with VBA

Need to figure out the number of characters in a range of selected text? Here's how to do it in VBA.

Discover More

Determining if a Text Selection Exists

Macros are often designed to be run on just a selected portion of a document. It is a good idea to make sure that the user ...

Discover More

Displaying a Message in the Status Bar

A great place for your macro to display status information is, well, in the status bar. Displaying the information is easy, ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments for this tip:

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 7 + 8?

2015-11-16 08:38:42

Alyssa

Hello,
I made a template with Checkboxes that hide/show certain tables with fill in content controls. IN my tmeplate the boxes work perfect and hide and show the bookmarked tables they refer to. But when I open a new document from the template, there seems to be nologic to what bookmarked tbale opens. For instance CheckMarkNew opens TableTools.
I even looked to make sure the book mark still took me to the correct table and it does.

What do you think the problem is?

here is an example of the code:


Private Sub CheckBoxNew_Click()

Bookmarks("NewTable").Range.Font.Hidden = CheckBoxNew.Value = False

End Sub


2014-12-12 05:01:54

Laurent

Hi Allen,

I would like to know if there is a limit in bookmarks numbers ? At the moment, there is a problem with one of my Word 2010 macro. Use to now, until 402 bookmarks, it was ok. But, beyond 402 bookmarks, there's a bug in execution.

Regards from France,

Laurent


Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.

Links and Sharing
Share