Folder contents

How do I find the number of items in a folder? For example if the folder has 100 Excel worksheets, how can I find this?
ConernestoAsked:
Who is Participating?
 
GrahamSkanConnect With a Mentor RetiredCommented:
You could try a macro like this:
Sub ListXlFiles()
    Dim strFileName As String
    Dim strFolder As String
    Dim iCount As Integer
    strFolder = "C:\MyFolder"
    strFileName = Dir$(strFolder & "\*.xl")
    Do Until strFileName = ""
        iCount = iCount + 1
        strFileName = Dir$()
    Loop
   MsgBox "There are " & iCount & " relevant files in the folder"
End Sub

Open in new window

0
 
GrahamSkanRetiredCommented:
Note that a Worksheet is a part of a Workbook file. It is not a stand-alone entity.
0
 
ConernestoAuthor Commented:
I really meant the number of workbooks. The extension of these particular workbooks is .xsl
0
 
GrahamSkanRetiredCommented:
OK see if it works. It should look for most types of Excel file.
0
All Courses

From novice to tech pro — start learning today.