Searching on multiple keywords

  • Thread starter Thread starter S.J. Lean
  • Start date Start date
S

S.J. Lean

Is there any way I can get Word to search not on one word,
but on a whole list of words? I need to scan a very long
document text for possible occurrences of about a thousand
different names and flag them with say an asterisk, but I
don't want to have to do it manually one at a time. Any
ideas?

S.J. Lean
 
If the list of words that you are looking for are in a document named
listdoc arranged, one to each paragraph, that is

fox¶
dog¶

and you run the following macro when you have the document that you want to
search as the active document, it will do what you want

Dim ListDoc As Document, Target As Document, myword As String, i As Long,
myrange As Range
Set Target = ActiveDocument
Set ListDoc = Documents.Open("d:\Documents\Listdoc.doc") 'change the path
and name of the document as necessary
Target.Activate
For i = 1 To ListDoc.Words.Count - 1 Step 2
myword = ListDoc.Words(i).Text
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:=myword, MatchWholeWord:=True,
Wrap:=wdFindStop, Forward:=True) = True
Set myrange = Selection.Range
myrange.InsertAfter "*"
Loop
End With
Next i


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.
Hope this helps
Doug Robbins - Word MVP
 
Back
Top