Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, 2021, and Word in Microsoft 365. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Determining the Number of Bookmarks Defined in a Document.
If you are writing a macro, you can determine the number of bookmarks defined in a document by using the Count property with the Bookmarks collection object. This is done using the following VBA syntax:
x = ActiveDocument.Bookmarks.Count
where x is the variable you can then use in other VBA macro lines.
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (12096) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, 2021, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word here: Determining the Number of Bookmarks Defined in a Document.
The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2019. Spend more time working and less time trying to figure it all out! Check out Word 2019 For Dummies today!
Need to get rid of a lot of bookmarks all at once? Word doesn't provide a way to do it, but you can use the short macro ...
Discover MoreWhen you do a search and replace operation in Word, it is possible that you could inadvertently wipe out a bookmark or ...
Discover MoreWhen creating a macro, you may need to determine the names of the bookmarks in the document. You can do this using the ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2024-01-16 10:08:16
Andrew
To NOT include hidden bookmarks in the count, try using "ActiveDocument.Bookmarks.ShowHidden = False" before the call to "ActiveDocument.Bookmarks.Count". See https://learn.microsoft.com/en-us/office/vba/api/word.bookmarks.showhidden.
2024-01-14 10:22:40
John Patton
AllennnTry using ChatGPT to write VBA Word macros. It’s really good starting point. I wrotenn“Write VBA Word macro to delete styles not in a list”nnHere is result - not perfect but good nnSub DeleteStylesNotInList()n Dim styleList As Variantn Dim style As Stylen n ' Define the list of styles to keepn styleList = Array("Normal", "Heading 1", "Heading 2", "CustomStyle1", "CustomStyle2")n n ' Loop through each style in the documentn For Each style In ActiveDocument.Stylesn ' Check if the style is not in the listn If Not IsInArray(style.NameLocal, styleList) Thenn ' Delete the stylen style.Deleten End Ifn Next stylenEnd SubnnFunction IsInArray(valueToFind As Variant, arr As Variant) As Booleann ' Check if a value is in an arrayn Dim element As Variantn For Each element In arrn If element = valueToFind Thenn IsInArray = Truen Exit Functionn End Ifn Next elementn IsInArray = FalsenEnd Function
2024-01-13 05:44:16
Ken Endacott
The bookmarks count includes hidden bookmarks whose name starts with an underscore for example _Toc156072804.nnNot included in the count are the 16 predefined bookmarks whose name starts with a backslash:n\Cell \Char \Doc \EndOfDoc \EndOfSel \HeadingLevel \Line \Page \Para \PrecSel2 \PrevSel1 \Section \Sel \StartOfDoc \StartOfSel \Table
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2026 Sharon Parq Associates, Inc.
Comments