LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Search for word in a file in Folder using VBA?

That came out a bit jumbled:

Sub AA()
Dim fs As FileSearch
Set fs = Application.FileSearch
fs.NewSearch
With fs
With .PropertyTests
.Add _
Name:="Text or Property", _
Condition:=msoConditionIncludesPhrase, _
Value:="horse"
End With
.LookIn = "E:\Data"
.SearchSubFolders = False
.Filename = "*"
.MatchTextExactly = False
.FileType = msoFileTypeAllFiles
End With
If fs.Execute() 0 Then
MsgBox "There were " & _
fs.FoundFiles.Count & _
" file(s) found."
For i = 1 To fs.FoundFiles.Count
msgbox fs.FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End Sub

--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote in message
...
search for a word in files in a folder


I take it he is looking in the content of the files in a folder to see if
they contain a specified word.

I would see it as a propertytest setting in the FileSearch object, but it
is poorly documented.

Sub AA()Dim fs As FileSearchSet fs = Application.FileSearchfs.NewSearch
With fs With .PropertyTests .Add Name:="Text or Property", _
Condition:=msoConditionIncludesPhrase, _ Value:="horse" End With
.LookIn = "E:\Data" .SearchSubFolders = False .Filename = "*"
.MatchTextExactly = False .FileType = msoFileTypeAllFilesEnd With If
fs.Execute() 0 Then MsgBox "There were " & fs.FoundFiles.Count &
_ " file(s) found." For i = 1 To fs.FoundFiles.Count
MsgBox fs.FoundFiles(i) Next i Else MsgBox "There were no
files found." End IfEnd Subdid work for me looking for the word "horse"
as an example.
--
Regards,
Tom Ogilvy

"Jim Cone" wrote in message
...
Are you looking for a folder or are you looking for a file?
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware



wrote in message
Hi,
Does anyone know how to search for a word in files in a folder using
VBA? I know the code to search and return folder names but I want to
look for a word in a folder like in using windows search function to
"find a word or phrase" in a file.
Thanks a lot
MW







 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Microsoft Search opens when I click on a file folder tedster Setting up and Configuration of Excel 1 December 10th 08 06:20 PM
how to search a word in a excel file which appears twice Jegadeesan P r Excel Discussion (Misc queries) 0 October 26th 06 11:26 AM
search for a word in csv file cgkuhle Excel Discussion (Misc queries) 1 May 15th 06 01:53 PM
Word and Excel crash when I try to open a folder to get to a file DGD41 Excel Discussion (Misc queries) 7 April 15th 06 09:14 PM
Browse for file and set initial folder to search [email protected] Excel Programming 3 January 30th 06 08:34 PM


All times are GMT +1. The time now is 09:52 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"