Count of workbooks in a directory

  • Thread starter Thread starter David
  • Start date Start date
D

David

I need to get a count of the number of workbooks in a
directory I specify.

I see an example someone else used (after a ChDir
command):

CountA = Application.Workbooks.Count

but this doesn't work and I can't see how the code would
look to count the number of workbooks only in a directory
I specify.

Thanks for your help. I'm new and stupid.

David
 
Try this

Sub test()
Dim foldername As String
foldername = "C:\Data"
With Application.FileSearch
.NewSearch
.LookIn = foldername
.SearchSubFolders = False
.FileType = msoFileTypeExcelWorkbooks
If .Execute() > 0 Then
MsgBox .FoundFiles.Count & " Excel files were found"
Else
MsgBox "There were no files found."
End If
End With
End Sub
 
Back
Top