How do I create a program to search a list of words within a doc?

T

tskn

I want a program to search and identify a word/words/characters (which I
specify in a list) that appears within a WORD document. As I have a long
list of word/words/characters, the Search/find function is not practical. I
want the program to compare the word document against every reference on my
list of word/words/characters and identify where these words show up in the
Word Doc. I have used such a program in the past and would like to recreate
it. I am currently using microsoft office 2003. thank you.
 
H

Helmut Weber

Hi,

I don't think that there is a faster way
to find a word in a word.doc then to
use Word's find function.

Might be different if you search in
a txt-file or if you put all of the txt-file
into a string.
 
T

tskn

I'd be happy to search in a txt-file or put all of the txt-file into a
string. I just need to know how to link the txt-file with the WORD file and
set it up. Would appreciate any advice.
 
J

Jonathan West

I would suggest that you copy the entire Activedocument.Range.Text property
into a String. You can then use the Instr function to check whether each
word in turn in your list is present. If you need to get the exact location,
you can then do a Find on the document itself.

If you need the search to be case-insensitive, convert the string to
lowercase after extracting it, and make sure you have loawercase versions of
your list of words before using Instr.

If you have a large number of words to check, and only a few of them likely
to be present, the Instr approach will probably be much quicker.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
H

Helmut Weber

Hi,

that wasn't what I meant.
I meant not to use a Word-file at all
I meant search in a string for other strings,
which are listed in a txt-file, or put into an array first.
 
T

tskn

Hi, maybe my original post was unclear. The program that I had used in the
past was a macro that enabled me to maintain a "LIST of words" (separated by
commas). I think this was a txt/string/array, but I'm not sure of the
terminology.

When I had a WORD FILE (which I have very many of), I could run a macro and
it would find any references specified in my "LIST of words" and identify
them in the WORD FILE. I would like to recreate this function. Any
suggestions of how to do this? Thanks again.
 
P

Peter Jamieson

Have you considered using Word's facility for using a Concordance file (look
up Concordance in Word Help) to create an Index? You only get to see which
page a word appears on, but maybe that's enough.

Peter Jamieson
 

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