FileSearch

  • Thread starter Thread starter Skimrhett
  • Start date Start date
S

Skimrhett

This isn't really a question about the code itself (most of it's copie
from a textbook), but why it is so slow. I get what I want - looking i
a folder for all excel files - but it's really slow, as if it's lookin
in my whole drive, even when I specify a specific folder. Any ideas wh
it's so slow?

Thanks in advance


---------------------------------------
Sub FindExcelFilesInFolder()

Dim FS As Office.FileSearch
Dim vaFileName As Variant
Dim stMessage As String
Dim i As Long
Dim iCount As Long
Dim varFiles() As Variant

Set FS = Application.FileSearch

With FS
'Clear old search criteria
.NewSearch

'directory to search
.LookIn = ThisWorkbook.Path & Application.PathSeparator & "Files"

'don't include subfolders in search
.SearchSubFolders = False

'look for excel files
.Filename = "*.xls"

'carry out search and capture number of files found
iCount = .Execute

stMessage = Format(iCount, "0 ""Files Found""")

'List the files in the FoundFiles collection

For Each vaFileName In .FoundFiles
stMessage = stMessage & vbCr & vaFileName
Next vaFileName

MsgBox stMessage


End With

End Su
 
Try an modify this to suit

Sub GetFileList2222()
Dim iCtr As Integer

With Application.FileSearch
.NewSearch
.LookIn = "c:\aa"
.SearchSubFolders = True
.Filename = ".xls"
If .Execute > 0 Then
For iCtr = 1 To .FoundFiles.Count
Cells(iCtr, 1).Value = .FoundFiles(iCtr)
Next iCtr
End If
End With
End Sub
 
Back
Top