View Single Post
 
Old 08-07-2022, 01:44 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

Okay Andrew, from your previous help on a different question, I managed to get these Endnote References removed by doing a Do While after the find. Just tested this on a 285 page document with 15 instances, and it finished in just 5 seconds. Text pastes into Rich Text Editors fine now. Whew, this was a tough one!
Code:
' Remove Endnote Reference style from superScript numbers
Dim rngCheck As Range
Dim rngChar As Range

With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Format = False
    .Forward = True
    .Font.Superscript = True ' Finds only superScripts
    .Wrap = wdFindStop
    .MatchWildcards = True ' Allows regex for .Text
    .Text = "[0-9]{1,}" ' Finds only numbers, 1 or more
    .Replacement.Text = ""
  End With
  
  Do While .Find.Execute = True ' When we get a hit, do this
    For Each rngChar In .Characters
      If rngChar.Style = "Endnote Reference" Then
        rngChar.Font.Reset ' Remove the Endnote Reference character style
        rngChar.Font.Superscript = True
      End If 'rngChar.Style
    Next rngChar
    .Collapse wdCollapseEnd
  Loop
End With 'ActiveDocument.Range
Reply With Quote