View Single Post
 
Old 06-08-2013, 12:31 PM
Fgrable Fgrable is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jun 2013
Location: Chicago
Posts: 1
Fgrable is on a distinguished road
Smile Had some problems with one macro suggested

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:
for a multi-word string as part of the Find array, you simply input that between the commas. For example:
StrFnd = "dog,cat,pig,this and that,horse,man"
However, when I attempted to run my macro on the document with a multi-word string, it failed. Here's my macro which mirrors what was suggested early on in this thread (but using some words and phrases that I am trying to find):
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
Through intuition and dinking around, I found that if I changed

.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
Reply With Quote