Identifying Duplicate Bookmarks

Written by Allen Wyatt (last updated August 1, 2026)

Nigel has a document in which bookmarks have been used extensively. He wonders if there is an easy way to identify bookmarks that either point to the same document location or that overlap with one another.

There is no built-in feature in Word to highlight duplicate or overlapping bookmarks. However, because Word stores each bookmark's starting and ending character positions and makes those positions available to VBA, you can identify duplicates and overlaps using a macro. The trick is to recognize where bookmarks can occur and how the start/end locations can relate to each other.

Here is a macro that will create a new document and provide a report about the bookmarks in the current document:

Sub CheckBookmarks()
    Dim bm1 As Bookmark
    Dim bm2 As Bookmark
    Dim docSource As Document
    Dim docTarget As Document
    Dim i As Long
    Dim j As Long
    Dim countDuplicates As Long
    Dim countContains As Long
    Dim countOverlaps As Long
    Dim sTemp As String

    Set docSource = ActiveDocument
    If docSource.Bookmarks.Count < 2 Then
        MsgBox "Fewer than 2 bookmarks; nothing to compare.", vbInformation
        Exit Sub
    End If

    Set docTarget = Documents.Add
    countDuplicates = 0
    countContains = 0
    countOverlaps = 0

    Selection.TypeText "=== BOOKMARK AUDIT REPORT ===" & vbCrLf
    Selection.TypeText "Total bookmarks: " & _
      docSource.Bookmarks.Count & vbCrLf & vbCrLf

    For i = 1 To docSource.Bookmarks.Count - 1
        Set bm1 = docSource.Bookmarks(i)

        For j = i + 1 To docSource.Bookmarks.Count
            Set bm2 = docSource.Bookmarks(j)
            sTemp = ""

            If bm1.Range.InStory(bm2.Range) Then
                If bm1.Start = bm2.Start And bm1.End = bm2.End Then
                    sTemp = "[EXACT MATCH] '" & bm1.Name & "' and '" & _
                      bm2.Name & "' have the same start/end positions"
                    countDuplicates = countDuplicates + 1
                ElseIf bm1.Start = bm1.End And bm1.Start >= bm2.Start _
                  And bm1.Start <= bm2.End Then
                    sTemp = "[CONTAINED] Zero-length bookmark '" & _
                      bm1.Name & "' is within '" & bm2.Name & "'"
                    countContains = countContains + 1
                ElseIf bm2.Start = bm2.End And bm2.Start >= bm1.Start _
                  And bm2.Start <= bm1.End Then
                    sTemp = "[CONTAINED] Zero-length bookmark '" & _
                      bm2.Name & "' is within '" & bm1.Name & "'"
                    countContains = countContains + 1
                ElseIf bm1.Start >= bm2.Start And bm1.End <= bm2.End Then
                    sTemp = "[CONTAINED] '" & bm1.Name & _
                      "' is completely within '" & bm2.Name & "'"
                    countContains = countContains + 1
                ElseIf bm2.Start >= bm1.Start And bm2.End <= bm1.End Then
                    sTemp = "[CONTAINED] '" & bm2.Name & _
                      "' is completely within '" & bm1.Name & "'"
                    countContains = countContains + 1
                ElseIf bm1.Start < bm2.End And bm1.End > bm2.Start Then
                    sTemp = "[PARTIAL OVERLAP] '" & bm1.Name & "' and '" & _
                      bm2.Name & "' partially overlap each other"
                    countOverlaps = countOverlaps + 1
                End If
            End If

            If Len(sTemp) > 0 Then Selection.TypeText sTemp & vbCrLf
        Next j
    Next i

    Selection.TypeText vbCrLf & "Audit Complete" & vbCrLf
    Selection.TypeText "    Duplicate pairs: " & countDuplicates & vbCrLf
    Selection.TypeText "    Containment pairs: " & countContains & vbCrLf
    Selection.TypeText "    Overlap pairs: " & countOverlaps & vbCrLf

    MsgBox "Bookmark audit finished.", vbInformation
End Sub

There are a few things to keep in mind with a macro such as this. First, the macro doesn't do any evaluation of the hidden bookmarks maintained by Word. This should not be an issue for Nigel's purposes, as he doesn't mention hidden bookmarks in his initial query.

Another thing to remember is that this macro doesn't list all bookmarks in its output. It only deals with bookmark pairs where there is some sort of overlap between the start/stop positions. These are the relationships highlighted in the output:

  • Start/end positions are the same for a bookmark pair.
  • A zero-length bookmark is contained within another bookmark.
  • A bookmark is contained within another bookmark entirely.
  • A portion of one bookmarks overlaps with another bookmark.

Note that the macro only looks at bookmark pairs within the same story. This is because it doesn't make sense to compare a bookmark in one story (such as a header) with a bookmark in another story (such as the main text).

Finally, the macro only reports on what it finds. It does not make any changes to the document, such as deleting or repositioning bookmarks. Any necessary changes should be done manually, based on the output of the macro.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13990) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365.

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

Renaming Worksheets Based On a List

Renaming a worksheet within a macro is a relatively easy task. When you start renaming based on a range of names, though, ...

Discover More

Understanding Nonprinting Characters

Even characters that print nothing still take space in your document. Characters such as tabs, spaces, breaks, and the ...

Discover More

Embedding an Excel Worksheet

Word and Excel are both integral parts of Microsoft's Office suite of applications. As such, Word allows you to embed ...

Discover More

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!

More WordTips (ribbon)

Setting a VBA Variable from a Bookmark

Bookmarks are quite helpful in a document. You may want to transfer the contents of a bookmark into a macro variable in ...

Discover More

Getting Bookmark Information in VBA

Bookmarks are a handy way to "mark" locations within a document. If you are creating a macro that processes the document ...

Discover More

Seeing Where Bookmarks Are

Bookmarks can be great for referencing and finding portions of your document. If you want to easily see where the ...

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

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}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. 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 1 - 0?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

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.

Videos
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.