Question
-
Topic
-
Why does this word macro keep freezing?
LockedI used the macro provided by the following:
Macro trick: How to highlight multiple search strings in a Word document
I ended up inputting 226 words in it. Now every time I use it, I get the spinning wheel and have to force-close word. Word restarts, the file recovers, and all my terms are highlighted perfectly. This is great, but I can’t exactly share the macro with co-workers in this state.
Below is an abbreviated version of what I have I will use “(…)” to skip over the list of words:
———
Sub litglossaryterms()
Dim Word As range
Dim WordCollection(0 To 225) As StringWordCollection(0) = “Abstention”
WordCollection(1) = “Ad hoc arbitration”
(…)
WordCollection(225) = “Work Product Doctrine”Options.DefaultHighlightColorIndex = wdYellow
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Highlight = TrueFor Each Word In ActiveDocument.Words
For Each Words In WordCollection
With Selection.Find
.Text = Words
.Replacement.Text = “”
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Next
NextEnd Sub