Search for specific words in a document using an external list?

G

Guest

Hello,

I have a word document (for example, I’ll call it ‘Article.doc’) which is
rather large, containing certain news articles.

I wish to do a search/find and identify specific key words in ‘Article.doc’.
However, the list of possible words in ‘Article.doc’ that I wish to find (if
they are there), number about 500.

I have this list of words that I want to be found stored in a separate
document that is always being updated/changed. (For example, I’ll call this
document ‘List.doc’)

I do not want to have to go and use the Find Feature built-in to MS Word and
copy/paste all 500 words individually and search ‘Article.doc’ to see if they
are present.

So I was curious, is there a way I can get MS Word to take/store the list of
words in ‘List.doc’ and then go through ‘Article.doc’ and find any instances
of any of the words from the ‘List.doc’.
If possible I would like to also go one step further, and not only find
instances of any of the 500 words in the ‘Article.doc’, but to also highlight
them in yellow.

If you have any help or suggestions, I would greatly appreciate it :-D

Thankyou kindly for you time,

Kind Regards
KJ
 
K

Klaus Linke

Hi KJ,

I think this problem has come up a few times. You might be able to find
macros if you google the Word newsgroups and posts from Doug Robbins, IIRC,
though I didn't find anything in a quick search.
It shouldn't be too hard to write something from scratch, either.

You can use a sub to hightlight some specific word:

Sub HighlightWord(strWord As String)
'
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Replacement.Highlight = True
With Selection.Find
.Text = strWord
.Wrap = wdFindContinue
.Format = True
.MatchCase = True
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

The rest of the problem would be to read the text from List.doc into a
Variant, split it into words (say using Split, and vbCr as the delimiter),
and run HighlightWord(myArray(i)) for each of the words in the array.

Regards,
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top