Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-12-2022, 06:01 AM
BrianHoard BrianHoard is offline Trouble removing cross-references Windows 10 Trouble removing cross-references Office 2019
Advanced Beginner
Trouble removing cross-references
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

I am trying to clean up text in Word before pasting into an HTML editor, and I keep getting what I believe are remnants of cross-reference information.

Attached is a sample document with the text, a1 b2. The numbers are superscript.

Notice how the superscript 2 has extra information once pasted into the HTML editor. I don't know how to find this information in Word where I can remove it.


Here's what I'm seeing when the text is pasted into HTML:
Code:
<p>a1 b<a name="_Ref111185707">2</a></p>
How can I remove this _Ref... information before copying from Word?

I was able to see the problem after extracting the .docx file, and looking at word/document.xml where the Bookmark and _Ref information is apparent. I'm attaching a screenshot of this file where I've highlighted the problem area.
Attached Images
File Type: jpg snap.jpg (122.6 KB, 4 views)
Attached Files
File Type: docx refTest.docx (11.8 KB, 5 views)
Reply With Quote
  #2  
Old 08-13-2022, 09:35 PM
macropod's Avatar
macropod macropod is offline Trouble removing cross-references Windows 10 Trouble removing cross-references Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 08-14-2022, 06:51 AM
BrianHoard BrianHoard is offline Trouble removing cross-references Windows 10 Trouble removing cross-references Office 2019
Advanced Beginner
Trouble removing cross-references
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

So glad you found this, can't wait to try your steps. I'm hoping I'll be able to do as you say via VBA. I'll try recording a macro of this and see if I can write a script to clean these up.
Reply With Quote
  #4  
Old 08-14-2022, 12:06 PM
BrianHoard BrianHoard is offline Trouble removing cross-references Windows 10 Trouble removing cross-references Office 2019
Advanced Beginner
Trouble removing cross-references
 
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
  #5  
Old 08-14-2022, 03:12 PM
macropod's Avatar
macropod macropod is offline Trouble removing cross-references Windows 10 Trouble removing cross-references Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Somewhat simpler:
Code:
Sub KillAllBookmarks()
With ActiveDocument
  Do While .Bookmarks.Count > 0
     .Bookmarks(1).Delete
  Loop
End With
End Sub
and, if you only want to delete hidden bookmarks, more reliably:
Code:
Sub KillHiddenBookmarks()
Dim i As Long, bHid As Boolean
With ActiveDocument
  bHid = .Bookmarks.ShowHidden
  .Bookmarks.ShowHidden = True
  For i = .Bookmarks.Count To 1 Step -1
     With .Bookmarks(i)
      If Left(.Name, 1) = "_" Then .Delete
     End With
  Next
  .Bookmarks.ShowHidden = bHid
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 08-14-2022, 03:19 PM
BrianHoard BrianHoard is offline Trouble removing cross-references Windows 10 Trouble removing cross-references Office 2019
Advanced Beginner
Trouble removing cross-references
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

Thanks again! I'm learning so much from you.
Reply With Quote
  #7  
Old 08-14-2022, 04:04 PM
Guessed's Avatar
Guessed Guessed is offline Trouble removing cross-references Windows 10 Trouble removing cross-references Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Note that the statement "Hidden bookmarks are automatically inserted when cross-references are inserted into the document." is somewhat misleading because it stretches a bit further than when the user explicitly adds a CrossRef.

If you build or refresh a Table of Contents or a Table of Figures then there will also be a cross-reference to each heading/caption included. So adding a TOC will insert a bunch of hidden bookmarks.

If you run a macro to remove hidden bookmarks you will break the TOC hyperlink functionality but it will restore itself if you refresh the TOC again (and recreate all those bookmarks).
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #8  
Old 08-14-2022, 05:10 PM
BrianHoard BrianHoard is offline Trouble removing cross-references Windows 10 Trouble removing cross-references Office 2019
Advanced Beginner
Trouble removing cross-references
 
Join Date: Jul 2022
Location: Haymarket, VA USA
Posts: 85
BrianHoard is on a distinguished road
Default

Wow, good to know. Thanks for the information! I'm working to help a team of many editors who edit in Word, and have to copy/paste from Word into a web page for their final reports. I managed to automate a lot of their endnote processing, renumbering, and handling duplicates. But when they pasted from Word to the website, we were getting problems with these hidden bookmarks.
I'll have to make sure none of them are using TOC in their documents. Or maybe I can find a way within my code that's causing these hidden bookmarks, so I am only deleting the ones created during my scripts.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble removing cross-references Trouble with Bulk Removing Unusual Footnotes CrossReach Word 3 06-25-2019 03:00 PM
About Cross-references mohsen.amiri Word 1 01-19-2017 10:35 AM
Convert manual cross references in footnotes to other footnotes to automatic cross references ghumdinger Word VBA 7 11-20-2014 11:47 PM
Trouble removing cross-references Cross-References acolussi Word 9 05-16-2013 02:11 AM
Trouble removing cross-references Trouble Removing Password cure4glass Word 1 02-17-2012 07:19 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:32 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft