View Single Post
 
Old 08-14-2022, 12:06 PM
BrianHoard BrianHoard is offline Windows 10 Office 2019
Advanced Beginner
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
What the _Ref111185707 refers to is a hidden bookmark, not a cross-reference. In your attachment, that bookmark is applied to the '2'. Delete the hidden bookmark via the Insert|Bookmark dialogue (check the 'hidden bookmarks' option to see it) and all will be well.
Okay, Macropod, I think I have it now. Thanks a million for your sage advice! I would never have figured this out on my own.

I also found where these hidden bookmarks are coming from. I wasn't creating them directly, but as I was creating and deleting cross-references, Word was creating hidden bookmarks each time.
I found this info from:Bookmarks.ShowHidden property (Word) | Microsoft Docs
"Hidden bookmarks are automatically inserted when cross-references are inserted into the document."

In case it helps someone else with a similar problem, here's my script to delete only hidden bookmarks from a document.
Code:
Sub bhh_deleteHiddenBookmarks()
  ' Delete hidden bookmarks
  
  ' NOTE: Hidden bookmarks may be the result of inserting cross-references into the document, and removing the cross-reference.
  ' As found at: https://docs.microsoft.com/en-us/office/vba/api/word.bookmarks.showhidden
  ' "Hidden bookmarks are automatically inserted when cross-references are inserted into the document."
  ' Hidden bookmark names begin with an underscore _, like _Ref...

  Dim bool_showHiddenBms As Boolean
  Dim bms As bookmarks
  Dim bm As Bookmark
  
  Set bms = ActiveDocument.bookmarks
  
  bool_showHiddenBms = bms.ShowHidden ' Store original state for showing hidden bookmarks
  ' This option is a checkbox from Insert > Bookmark within Word.

  ' Ensure show hidden bookmarks is turned on for this script.
  bms.ShowHidden = True

  ' Loop through all bookmarks, delete hidden ones.
  For Each bm In bms
    If Left(bm.Name, 1) = "_" Then ' If the first character of .Name is an underscore,
      Debug.Print ("Deleting hidden bookmark: " & bm.Name)
      bm.Delete
    End If
  Next bm

  ' Set hidden bookmark option back to starting state
   bms.ShowHidden = bool_showHiddenBms

  Exit Sub
End Sub ' bhh_deleteHiddenBookmarks
Reply With Quote