Jaafar Tribak
Well-known Member
- Joined
- Dec 5, 2002
- Messages
- 9,779
- Office Version
- 2016
- Platform
- Windows
Greetings all,
The following code simply performs a file search on the C root using the FileSearch object. I set up the search criteria so that the file search takes a while in order to illustrate this problem.
The problem with this search , as you know, is that it causes the application to hung until the search is finished making any user interaction with the application impossible.
Depending on the search criteria, the search can take a very long time. I am wondering if there is a way around this problem.
I don't want to run this code on another background process/App and I know that i could stick a DoEvents within a Dir file search but that's not what i am asking. I really need to use the FileSearch object.
Any thoughts on this will be much appreciated.
Regards.
The following code simply performs a file search on the C root using the FileSearch object. I set up the search criteria so that the file search takes a while in order to illustrate this problem.
Code:
Sub test()
Dim oFileSearch As FileSearch
Set oFileSearch = Application.FileSearch
With oFileSearch
.NewSearch
.LookIn = "C:"
.SearchSubFolders = True
.Filename = "ab" [COLOR=seagreen]' just random chars for the sake of this exmpl.[/COLOR]
.MatchTextExactly = False
.FileType = msoFileTypeAllFiles
.Execute
For i = 1 To .FoundFiles.Count
strFiles = strFiles & vbCrLf & .FoundFiles(i)
Next i
End With
MsgBox strFiles
Set oFileSearch = Nothing
End Sub
The problem with this search , as you know, is that it causes the application to hung until the search is finished making any user interaction with the application impossible.
Depending on the search criteria, the search can take a very long time. I am wondering if there is a way around this problem.
I don't want to run this code on another background process/App and I know that i could stick a DoEvents within a Dir file search but that's not what i am asking. I really need to use the FileSearch object.
Any thoughts on this will be much appreciated.
Regards.