Advertisement
Combreal

evolvedSearchWord.vba

Feb 16th, 2021
2,268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub hl01()
  2.     Dim Word As Range
  3.     Dim WordCollection(1) As String
  4.     Dim Words As Variant
  5.     Dim StoryRange As Range
  6.  
  7.     WordCollection(0) = "active"
  8.     WordCollection(1) = "door"
  9.  
  10.     For Each StoryRange In ActiveDocument.StoryRanges
  11.         StoryRange.HighlightColorIndex = wdNoHighlight
  12.     Next StoryRange
  13.  
  14.     Options.DefaultHighlightColorIndex = wdYellow
  15.     Selection.Find.ClearFormatting
  16.     Selection.Find.Replacement.ClearFormatting
  17.     Selection.Find.Replacement.Highlight = True
  18.     For Each Word In ActiveDocument.Words
  19.         For Each Words In WordCollection
  20.             With Selection.Find
  21.                 .Text = Words
  22.                 .Replacement.Text = ""
  23.                 .Forward = True
  24.                 .Wrap = wdFindContinue
  25.                 .Format = True
  26.                 .MatchCase = False
  27.                 .MatchWholeWord = False
  28.                 .MatchWildcards = False
  29.                 .MatchSoundsLike = False
  30.                 .MatchAllWordForms = False
  31.             End With
  32.             Selection.Find.Execute Replace:=wdReplaceAll
  33.         Next
  34.     Next
  35. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement