#1
|
|||
|
|||
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> 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. |
#2
|
||||
|
||||
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] |
#3
|
|||
|
|||
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.
|
#4
|
|||
|
|||
Quote:
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 |
#5
|
||||
|
||||
Somewhat simpler:
Code:
Sub KillAllBookmarks() With ActiveDocument Do While .Bookmarks.Count > 0 .Bookmarks(1).Delete Loop End With End Sub 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] |
#6
|
|||
|
|||
Thanks again! I'm learning so much from you.
|
#7
|
||||
|
||||
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 |
#8
|
|||
|
|||
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. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |
Cross-References | acolussi | Word | 9 | 05-16-2013 02:11 AM |
Trouble Removing Password | cure4glass | Word | 1 | 02-17-2012 07:19 PM |