Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search word docs in a folder for certain text.

Status
Not open for further replies.

neemi

Programmer
May 14, 2002
519
GB
I have a requirement to create an automated search of word doc's in a folder for a particular word or pharse. Similar to how it is doe in windows, but I need this automated as part of my function.

I have a table created with the path names and file names of the documents to search. then I need to carry out the search and if a match is found the record in the table flagged.

But I need help wth carrying out the search of the text in vba.

advise apreciated.

regards,
neemi
 
sorry forgot to say the search needs to be carried out from access. I am currently using 2002
 
If the text is in the body of the documents, you will need to make an instance of Word, open the documents and search for the text. You can use standard search routines to do so.
Code:
With Selection.Find
  .Text = "search string"
  .Execute
  If .Found = True Then
     ' set your flag
  End If
End With

Gerry
My paintings and sculpture
 
In xp you can search inside documents:
Code:
With Application.FileSearch
    .NewSearch
    .LookIn = "c:\test"
    .SearchSubFolders = True
    .FileType = msoFileTypeWordDocuments
    .MatchTextExactly = True
    .TextOrProperty = "text to find"
    .Execute
    For i = 1 To .FoundFiles.Count
        MsgBox .FoundFiles(i)
    Next i
End With

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top