Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #21  
Old 05-26-2012, 06:11 PM
macropod's Avatar
macropod macropod is online now Find and highlight multiple words in MS Word document Windows 7 64bit Find and highlight multiple words in MS Word document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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
Some things to note:
• 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]
Reply With Quote
 

Tags
find, highlight, multiple keywords



Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and highlight multiple words in MS Word document Lost Word Document and cant find it!!! I saved it but it ISNT there!! 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

Other Forums: Access Forums

All times are GMT -7. The time now is 10:12 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft