Filesearch...

  • Thread starter Juan Carlos Biancotti
  • Start date
S

Steve Lang

Hola Juan Carlos,

If you are looking to search a folder of files to see if any have a specific
string, use something like this:

Sub foo()
Dim i As Long
Dim oRange As Range

With Application.FileSearch
'Search in foldername
.LookIn = "C:\Test"
.SearchSubFolders = False
.FileName = "*.doc"
.Execute
For i = 1 To .FoundFiles.Count
Documents.Open FileName:=(.FoundFiles(i))
With oRange.Find
.ClearFormatting
.Forward = True
.MatchWildcards = False
.Text = "Hello World"
.MatchCase = False
.Execute
End With
If oRange.Find.Found Then MsgBox "Text Found."
'Close document
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
Next i
End With

'clean up and exit
Set oRange = Nothing

End Sub

HTH and have a great day!

Steve Lang
 
Top