Why does this word macro keep freezing? - TechRepublic
Question
June 21, 2017 at 09:25 PM
rahskir

Why does this word macro keep freezing?

by rahskir . Updated 8 years, 11 months ago

I used the macro provided by the following:
https://www.techrepublic.com/article/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 String

WordCollection(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 = True

For 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
Next

End Sub

This discussion is locked

All Comments