![]() |
#25
|
|||
|
|||
![]()
I, too, had a need for finding multiple words in a word document and ran across this thread. I find that the initial macro offered works well for multiple single words. In the thread, it was suggested that the macro could find phrases by simply putting the phrase in-between the commas:
Quote:
Code:
Sub HiLightList() Application.ScreenUpdating = False Dim StrFnd As String, Rng As Range, i As Long StrFnd = "portable,residential,aquatic vessel,barrier,listed,labeled,flood hazard area,self-contained spa" For i = 0 To UBound(Split(StrFnd, ",")) Set Rng = ActiveDocument.Range With Rng.Find .ClearFormatting .Text = Split(StrFnd, ",")(i) .Replacement.ClearFormatting .Replacement.Highlight = True .Replacement.Text = "^&" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = True .Execute Replace:=wdReplaceAll End With Next Set Rng = Nothing Application.ScreenUpdating = True End Sub .MatchAllWordForms = False The macro runs and highlights the exact words and phrases that I asked it to find even those words or phrases have the plural "s" at the end. In other words, it will find and highlight only "barrier" in the word "barriers". And for a first pass, that is OK for my purposes because I just want to only locate the word or word phrase so I can make manual document changes, if I feel the change is needed. Questions: 1. I have a few phrases that contain the word "and". For example "hair and lint strainer". The macro will run, but it won't find the phrase. Any SIMPLE suggested modification to make the macro find this? 2. In searching for a solution to the problem I was having, I ran across someone who was talking about putting the words in an excel sheet (one column) and being able to make a Word macro go look to the excel document, pull the words from it (and I assume put them in comma delimited text format) and then use that for running the macro. I don't necessarily want to use Excel (but i could) but the idea made me think that instead of having to "rewrite" the macro for different word lists, I could have a generic "finder" macro that go to a specific file to get the words. That way, I could just have a simple word (or excel) file to maintain and run the macro on my documents using the words in that word (or excel) file. Any thoughts on this or would that take rocket scientists to work out? 2. This macro writing for Word is a nifty treat for oddball document manipulation. I am intrigued. How do I find out more about how to do this type of programming? It reminds me of AutoLisp in the AutoCad programs...rarely does anybody know of its capability but how powerful it can be for working on hundreds of projects. PS: Thank you Macropod for initially sharing your expertise on this subject. This macro is going to be very useful for me and my co-workers. Perhaps as I learn more, I'll come back with some more questions and ideas (hopefully new tricks I have learned!) Fred Last edited by macropod; 06-09-2013 at 04:19 AM. Reason: Added code tags & formatting |
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 |