ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Problems with Application.FileSearch (https://www.excelbanter.com/excel-programming/379520-re-problems-application-filesearch.html)

Jim Rech

Problems with Application.FileSearch
 
I ran your code repeatedly and each time it found the correct number of
files. That said, I have in the past had my own problems with FileSearch
not returning all the files I thought it should and I consider it to be
unreliable. I prefer the tried and true Dir method.

--
Jim
"kristinaol" wrote in message
...
I am trying to search for a bunch of files using Application.FileSearch.
Sometimes it works, but mostly it doesn't. It is as if some variable is
not
cleared, that the result from an old search is still in memory, and no new
search is performed when I try to run the script again. Does anyone have
any
ideas what is wrong?

The code looks as follows:
(Variables files and no_of_files are declared earlier)

With Application.FileSearch
.NewSearch
.LookIn = Path
.FileType = msoFileTypeExcelWorkbooks
If .Execute() 0 Then
ReDim files(1 To .FoundFiles.Count)
no_of_files = .FoundFiles.Count
Else
MsgBox "There were no files found."
Exit Sub
End If
End With





All times are GMT +1. The time now is 02:26 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com