How to Search in MS Word using VBA

A

Ashish Kanoongo

I would to create a ASP base search utility. In this asp page user enter his text in TEXT box, then like to search, this search string in all the word documents of particular folder. Then display a list of search result with highlighted text first 2-3 line of all those word document where this search is exist. Once user click any of the search result url, it will open word document and directly jump to selected page/text.

Is it possible or not? If yes let me guide in this matter. I know I can use index server, but the problem is that it is not jump to particular page of Word document where search is exist. If anyone help me in this matter, I can go for Index server options also.

I will be thankful in advance in reagrds any kind of help.

Ashish
 
D

Doug Robbins - Word MVP

I believe that the vba end of it is possible. You can get some clues from
the article "Find & ReplaceAll on a batch of documents in the same folder"
at:

http://word.mvps.org/FAQs/MacrosVBA/BatchFR.htm

If the text is found in a document, you would set a Range object to say the
..Range of the first paragraph of the document, and then using the default
..Text property of that range, you would have the text to display on your
form. You can use the .FullName property of the document object to get the
path\filename of the document for your hyperlink and then when the user
wants to go to the text in a particular document, you could use Instr() on
the .Range of the document to get the location where the text was found and
then collapse a Range object to that location and then select the Range to
display the text.

If might actually be better to use Instr() in the first instance rather than
an Edit>Find though the latter may be quicker.

--
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
I would to create a ASP base search utility. In this asp page user enter his
text in TEXT box, then like to search, this search string in all the word
documents of particular folder. Then display a list of search result with
highlighted text first 2-3 line of all those word document where this
search is exist. Once user click any of the search result url, it will open
word document and directly jump to selected page/text.

Is it possible or not? If yes let me guide in this matter. I know I can use
index server, but the problem is that it is not jump to particular page of
Word document where search is exist. If anyone help me in this matter, I can
go for Index server options also.

I will be thankful in advance in reagrds any kind of help.

Ashish
 

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