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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search phrases in office files using VBS

Status
Not open for further replies.

Guima1

IS-IT--Management
Joined
Jun 6, 2003
Messages
3
Location
BR
I am building an script that searches multiple string in all files on a directory. It's working when my string doesn't contains spaces. If there's a space on that, the script seaches each word at a time (LOGICAL OR). Due to the amount of files, I can't open them as file text, so I call Excel COM as indicated below. It seems that .matchTextExactly is not working on VBS. Someone has any clues about it?

'=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
' EXCEL FILES
'=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
'
Set openfile = Fsys.OpenTextFile("c:\excelfileswordlist.txt",1,0)
Do While openfile.AtEndOfStream = false
strSentence=openfile.Readline
Set oXL = WScript.CreateObject("Excel.Application")

With oXL.Application.FileSearch
.NewSearch
.MatchTextExactly = TRUE
.TextorProperty = strSentence
.LookIn = "C:\My documents"
.SearchSubfolders = true
.filename = "*.xls"


If .Execute()>0 Then
For i = 1 To .foundfiles.count
results.writeline (.foundfiles(i) & " , " & strSentence)
Next
Else
MsgBox "string not found"
End If
End With
oXl.Quit
Loop
 
Have you tried the RegExp object ?

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top