How do you search for keywords to sort a number of word documents

L

LM

I have a folder with hundreds of word documents I need to sort through to
identify relevant ones based on a small set of keywords. How do I do this?
Thank you!
 
D

DaveLett

Hi LM,

Start with the "How to read the filenames of all the files in a directory
into an array" article at
http://word.mvps.org/FAQs/MacrosVBA/ReadFilesIntoArray.htm
At the beginning of your routine, create an array of the words that you want
to look for, as in the following:

Dim aKeywords
aKeywords = Array("Keyword1", "Keyword2")

From the routine in the article, you will want to modify this part so that
it 1) looks for your keywords in the filename of the document or 2) opens the
document and looks for your keywords
For Counter = 0 To UBound(DirectoryListArray)
'Debug.Print writes the results to the Immediate window (press Ctrl + G
to view it)'
Debug.Print DirectoryListArray(Counter)
Next Counter

Here's an example for number 1.
Dim lKeywords As Long
For Counter = 0 To UBound(DirectoryListArray)
For lKeywords = LBound(aKeywords) To UBound(aKeywords)
'''if the name of the file contains the keyword (all lowercase)
'''then print the name of the file in the immediate window
If InStr(1, LCase(DirectoryListArray(Counter)),
LCase(aKeywords(lKeywords))) <> 0 Then
Debug.Print
End If
Next lKeywords
Next Counter

HTH,
Dave
 

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