Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
or...<g
"but I want to look for a word in a folder" -- Jim Cone San Francisco, USA |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Microsoft Search opens when I click on a file folder | Setting up and Configuration of Excel | |||
how to search a word in a excel file which appears twice | Excel Discussion (Misc queries) | |||
search for a word in csv file | Excel Discussion (Misc queries) | |||
Word and Excel crash when I try to open a folder to get to a file | Excel Discussion (Misc queries) | |||
Browse for file and set initial folder to search | Excel Programming |