View Single Post
 
Old 07-07-2020, 06:55 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,980
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

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
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote