View Single Post
 
Old 07-07-2020, 07:59 PM
MyUserName123 MyUserName123 is offline Windows 10 Office 2019
Novice
 
Join Date: Jul 2020
Posts: 10
MyUserName123 is on a distinguished road
Default

Quote:
Originally Posted by Guessed View Post
The easiest fix for the code is to temporarily hide the field codes while the macro is running.
Code:
Sub MarkIndexMacro()
  Dim myRange As Range, aFld As Field, sXE As String
  ActiveWindow.View.ShowHiddenText = False
    Set myRange = ActiveDocument.Range
    With myRange.Find
      .Font.Color = wdColorRed
      Do While .Execute
        sXE = Trim(myRange.Text)
        ActiveDocument.Indexes.MarkEntry Range:=myRange, Entry:=sXE
        myRange.Collapse Direction:=wdCollapseEnd
      Loop
    End With
  ActiveWindow.View.ShowHiddenText = True
End Sub

Hi, I tried your code with a couple of different files and it works great. Thank you for all your help.
Reply With Quote