![]() |
#21
|
||||
|
||||
![]()
Hi Chayes,
Since your list actually has a separate paragraph for each entry, there possibly aren't any sentence or line issues to worry about. One can simply highlight the whole paragraph. You can do that with the following version of the macro: Code:
Sub HiLightList() Application.ScreenUpdating = False Dim StrFnd As String, Rng As Range, i As Long, j As Long StrFnd = UCase("jewellery|ring|rings|napkin rings|watch|watches") For i = 0 To UBound(Split(StrFnd, "|")) Select Case i Mod 6 Case 0: j = 3 Case 1: j = 4 Case 2: j = 5 Case 3: j = 6 Case 4: j = 7 Case 5: j = 16 End Select Options.DefaultHighlightColorIndex = j Set Rng = ActiveDocument.Range With Rng.Find .ClearFormatting .Text = "[!^13]@<" & Split(StrFnd, "|")(i) & ">[!^13]{1,}" .Replacement.ClearFormatting .Replacement.Highlight = True .Replacement.Text = "^&" .Forward = True .Wrap = wdFindContinue .Format = True .MatchWildcards = True .Execute Replace:=wdReplaceAll End With Next Set Rng = Nothing Application.ScreenUpdating = True End Sub • the code highlights the different entries in of of six colours. This is managed via the Select Case ... Options.DefaultHighlightColorIndex = j lines. Although Word can apply highlighting in any of 16 colours, I didn't think you'd find black, white or dark highlights very useful, so only 6 are used. If you're not interested in having different colours, simply delete those lines. • given the different shadings, if you want to shade 'gold watch' differently from 'watch' (ie where the material isn't defined), you need to have the 'gold watch' entry appear after the 'watch' entry in the StrFnd list. • the macro uses a wildcard Find/Replace and looks for whole words. Thus, if you want to highlight entries with watch and watches, both need to be entered into the StrFnd list. Alternatively, if you wanted to have both singular and plural forms of a word (eg 'watch' and 'watches') given the same higlighting, replace the last character from the singular form with '[! ]@'. Thus 'watch' becomes 'watc[! ]@'. • it doesn't matter whether you input entries into the StrFnd list in upper or lower case - everything is converted to upper-case for the Find operation. • you must have a '|' character separating each entry in the StrFnd list.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
find, highlight, multiple keywords |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
APAV | Word | 9 | 10-09-2017 01:17 PM |
Highlight text and find next instance | DrDOS | Word | 0 | 11-15-2010 04:02 PM |
Lock words in a document, but allow for input within the document | tlinde | Word | 1 | 02-09-2010 09:07 PM |
FInd recurring words in Word 2003 | NJ007 | Word | 4 | 01-25-2010 03:11 PM |
find - reading highlight - highlight all / highlight doesn't stick when saved | bobk544 | Word | 3 | 04-15-2009 03:31 PM |