Macro to Search for Keyword in Files

I

Iggitha

I'm trying to set up a search for keywords in a specific set of files. I
don't want to have to go through and check the multitude of boxes over and
over again.
Ideally a macro button to execute such a search would be a Godsend.
Anybody have any ideas?

Thanx.
 
H

Helmut Weber

Hi Iggitha,

what Word-version?
I'm trying to set up a search for keywords

What keywords? Where do they come from?
Is there a list of the keywords somewhere?
in a specific set of files.
What is the specification?

Finally, store the results (yes, no) of the search? Where?

It ain't that easy.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
B

Bear

Iggitha:

I don't know the list rules -- am I allowed to talk about add-on tools? But
if I can, I'd like to suggest Jack Lyon's tools:

http://www.editorium.com/

I think MegaReplacer would help you lots and is probably less expensive than
developing the equivalent code yourself.

Bear
 
I

Iggitha

Gruss Gott Helmut-Thanks for your response...here are my answers to your
questions.

The version I'm using is Word 2003, and we're running Windows XP.

The Keywords would change depending on the subject matter that we are
looking for within the set of folders. These folders would always be the
same-they are final copies of letters archived by year. Each year we add a
new file.

The location of files is on a shared network drive.

If the results of the search were to be stored, it would be best if it were
on the local machine (c:\ drive).

I hope that clarifies things.
Danke,
Iggitha
 
I

Iggitha

Thanks Bear. I'll check it out. Not sure about rules...I'm a newbie...
Hope I didn't break any!
 
H

Helmut Weber

Hi Iggitha,

Bear's suggestions might be preferred.

If you want to learn it the hard way,
then here we go.

Starting from a new, blank document:
Sub Test()90067
Dim strDir As String ' a folder
Dim strDoc As String ' a document
Dim strKey As String ' a keyword
Dim DcmTmp As Document ' the doc which is searched for a keyword
Dim DcmPrm As Document ' the permanent doc to collect the results
Set DcmPrm = ActiveDocument
' make sure it is empty !

strKey = InputBox("keyword to search for")
strDir = "c:\test\word1\" ' fixed folder !
strDoc = Dir(strDir & "*.doc")
While strDoc <> ""
Set DcmTmp = Documents.Open(strDir & strDoc)
With DcmTmp.Range.Find
.Text = strKey
If .Execute Then
DcmPrm.Range.InsertAfter _
strKey & " was found in " & DcmTmp.FullName & vbCrLf
End If
End With
DcmTmp.Close
strDoc = Dir()
Wend

End Sub

There is a lot of flickering on the screen, despite of
Application.ScreenUpdating = False

But doesn't matter here, I think.

Note that this searches the document's main story.
Searching *all* of the doc, headers end footers,
text boxes, captions, whatsoever,
would be a quite different story.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 

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