![]() |
#2
|
||||
|
||||
![]()
How many words? One approach is to use a pair of arrays to hold the words and the colours associated with those words. e.g.
Code:
Sub Macro1() 'Graham Mayor - https://www.gmayor.com - Last updated - 29 Sep 2019 Dim vFindText As Variant Dim vColor As Variant Dim i As Long vFindText = Array("Lorem", "ipsum", "amet") 'The word list vColor = Array(wdYellow, wdTurquoise, wdBrightGreen) 'The same number of items in this list as in the word list For i = 0 To UBound(vFindText) Options.DefaultHighlightColorIndex = vColor(i) With Selection .HomeKey wdStory With .Find .ClearFormatting .Replacement.ClearFormatting .Text = vFindText(i) .Replacement.Text = "^&" .Replacement.Highlight = True .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchKashida = False .MatchDiacritics = False .MatchAlefHamza = False .MatchControl = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Execute Replace:=wdReplaceAll End With End With Next i End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
Tags |
highlighting, multiple, words |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Nanaia | Word VBA | 3 | 09-07-2018 02:13 PM |
How to find (highlight) two and more words in a list of 75k single words in Word 2010 | Usora | Word | 8 | 05-29-2018 03:34 AM |
![]() |
aolszewski | Word VBA | 3 | 11-23-2013 02:07 AM |
![]() |
zdodson | Word VBA | 1 | 07-11-2013 04:53 PM |
![]() |
bertietheblue | Word VBA | 9 | 07-01-2013 12:39 PM |