Folder contents

Posted on 2013-12-05
Last Modified: 2013-12-06
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?
Question by:Conernesto
  • 3
LVL 76

Accepted Solution

GrahamSkan earned 500 total points
ID: 39699804
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$()
   MsgBox "There are " & iCount & " relevant files in the folder"
End Sub

Open in new window

LVL 76

Expert Comment

ID: 39699811
Note that a Worksheet is a part of a Workbook file. It is not a stand-alone entity.

Author Comment

ID: 39699816
I really meant the number of workbooks. The extension of these particular workbooks is .xsl
LVL 76

Expert Comment

ID: 39699824
OK see if it works. It should look for most types of Excel file.

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you how to use shortcut menus in the Access run-time environment.
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question