View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
smokiibear smokiibear is offline
external usenet poster
 
Posts: 33
Default .filesearch trouble

I am using the following code to conduct a filesearch and write the files
found to an array:

k = 0
For i = 1 To UBound(myFolders)
With Application.FileSearch
.NewSearch
.LookIn = myFolders(i)
.SearchSubFolders = False
.FileName = "*.csv"
If .Execute() 0 Then
ReDim Preserve filelist(1 To k + .FoundFiles.COUNT)
For j = 1 To .FoundFiles.COUNT
k = k + 1
filelist(k) = .FoundFiles(j)
Next j
Else
MsgBox "There were no files found."
End If
End With
Next i

The code works well only the first time run after restarting excel.
However, if I have already run the code, then add files to any previously
selected paths, the code only sees the files that were there during the
first execution of the code?

Any ideas?

Smokii