0
votes

I have a template with highlighted text that the user is supposed to replace (such as "[Client]"). While doing so, the user always removes the highlighting.

I use an Autoclose macro to catch any remaining highlights:

Selection.Find.ClearFormatting
Selection.Find.Highlight = True
With Selection.Find
    .Text = ""
    .Replacement.Text = ""
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = False
    .MatchSoundsLike = False
    .MatchAllWordForms = False
End With
if Selection.Find.Execute then
  'Stop and warn the user
end if

Unfortunately, the macro always "finds" text that is no longer highlighted. After some debugging, I see that it gets caught on an individual letter, space, or even paragraph mark from which the highlighting was removed.

Even though there's no visible highlight, I tried selecting the word or paragraph (including the paragraph mark) and "removing" the highlight again. The macro still "catches" that text. The only thing that works is if I select the entire document and "remove" all highlights.

If I use the Find command manually (outside of the macro), it correctly shows no highlights. This problem only happens in the macro.

1

1 Answers

0
votes

Try recording a macro with you using the Find command manually. After the macro has finished recording review the code of the Macro. You may notice some differences in what the Macro recorded vs what you have in your VBA Sub.