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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

729 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