Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2005

Tip: Looking for answers? Try searching our database.

Finding a word and displaying results

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ffn - 13 Feb 2005 11:24 GMT
Hi there,

need help with how to go about writing VBA (or VB Script) that will look
into a directory for all .doc Word documents and see if the content of each
.doc file contains a certain keyword. For all .doc files that has content
that contains the keyword, display the files in a nice list.
Example usage: list all the .doc Word documents in C:\A\B that contains the
word "cat".

Any suggestions, directions, code much appreciated!
Thanks!
Doug Robbins - 13 Feb 2005 11:45 GMT
Modify the procedure in the article "Find & ReplaceAll on a batch of
documents in the same folder" at:

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

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> Hi there,
>
[quoted text clipped - 7 lines]
> Any suggestions, directions, code much appreciated!
> Thanks!
ffn - 14 Feb 2005 11:36 GMT
Thanks Doug,

that certainly helped. I have now modified the code to find a particular
text in the content of the file. Is there anyway that I can execute the
"find" and hide the window that is used to open each .doc file in the
directory to perform the "find"?
Right now, a window is opened and then closed each time it performs the
"find" as it iterates through the files.

Also, can someone direct me to where I can find out about displaying the
list of "found" files so that the user can click on a found file and open up
the document? Right now, I'm just returning the filename in a msgBox.

Cheers and thanks again.

> Modify the procedure in the article "Find & ReplaceAll on a batch of
> documents in the same folder" at:
>
> http://word.mvps.org/FAQs/MacrosVBA/BatchFR.htm
Doug Robbins - 15 Feb 2005 00:00 GMT
To get the filenames into a document, do something like this.

At the beginning the procedure, add

Dim target as Document
Set target = Documents.Add

Then at the point where you presently have the MsgBox, use

target.Range.InsertAfter [what you now have in the MsgBox command] & vbCr

Then, after the procedure has run, the target document should contain a list
of the files that contain the text.

If you then run a macro containing the following code, it should convert
each (full) filename into a hyperlink.

Dim i As Long, frange As Range
For i = 1 To ActiveDocument.Paragraphs.Count
   Set frange = ActiveDocument.Paragraphs(i).Range
   frange.End = frange.End - 1
   ActiveDocument.Hyperlinks.Add Anchor:=frange, _
   Address:=frange.Text
Next i

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> Thanks Doug,
>
[quoted text clipped - 15 lines]
>>
>> http://word.mvps.org/FAQs/MacrosVBA/BatchFR.htm
ffn - 19 Feb 2005 09:26 GMT
Hi Doug,

thanks again for very helpful tips. I was wondering if there is a way to
insert the found files (actually if they could be inserted as links as you
suggested, that's best) into a pop-up window rather than a new document.

Cheers.

> To get the filenames into a document, do something like this.
>
[quoted text clipped - 40 lines]
>>>
>>> http://word.mvps.org/FAQs/MacrosVBA/BatchFR.htm
Doug Robbins - 23 Feb 2005 02:41 GMT
I am not sure what you mean by a pop-up window.  However, you could populate
a listbox on a userform with the found files and have code in the useform
that would open a document that the user clicked on in that listbox.

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> Hi Doug,
>
[quoted text clipped - 49 lines]
>>>>
>>>> http://word.mvps.org/FAQs/MacrosVBA/BatchFR.htm
ffn - 24 Feb 2005 04:11 GMT
Sorry, I may be using incorrect terminology - a userform may be just what
I'm looking for...I'm quite new to VBA (2 1/2 weeks now)!

Basically, I would like the Macro to place the found files in some other
persistent window (form?) that the user can switch between that window/form
and the document he is working on.
In the result window/form, the user can click on any of the found files and
it would open up in Word.
Any files that are found are placed in the result window/form.

I'll try to read up on userforms...do you know of any particular tutorials
that are most relevant to my specifications?

Cheers and thanks.

>I am not sure what you mean by a pop-up window.  However, you could
>populate a listbox on a userform with the found files and have code in the
>useform that would open a document that the user clicked on in that
>listbox.
Doug Robbins - 24 Feb 2005 11:07 GMT
See the article "How to create a Userform" at:

http://word.mvps.org/FAQs/Userforms/CreateAUserForm.htm

to get started, but that is only a very simple example of what can be done.
When you find each file, you will use the .AddItem method of the listbox to
add it to a listbox.

You will need to dig into the help in the Visual Basic Editor to get up to
speed with all that you will need.  See how you go and post back here when
you get stumped.  The best way to learn however is to try and do it
yourself.
Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> Sorry, I may be using incorrect terminology - a userform may be just what
> I'm looking for...I'm quite new to VBA (2 1/2 weeks now)!
[quoted text clipped - 17 lines]
>>useform that would open a document that the user clicked on in that
>>listbox.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.