+ Reply to Thread
Results 1 to 5 of 5

Count Files in a folder and subfolders, with specific name

  1. #1
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Count Files in a folder and subfolders, with specific name

    I found this code which counts files in a folder & subfolders, with a specific string in the filename.
    I want to amend it so that it counts files with the same name as the active workbook.
    Criteria is:
    - Without specifying in the code what the active workbook name is.
    - Disregard the extension. Example, active workbook "MyFile.xlsx" counts "MyFile.pdf".
    - A full match is required, no wild cards.

    Does anyone have any pointers?

    Link.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Count Files in a folder and subfolders, with specific name

    Hi Excel_&_Help,


    Try the following code:
    Please Login or Register  to view this content.
    It is a best practice to declare all variables. If you misspell a variable in your code, VBA will silently assume it is a Variant variable and go on executing with no clue to you that you have a bug. Go to the VBA development window, click Tools, Options, and check "Require Variable Declaration." This will insert the following line at the top of all new modules:
    Please Login or Register  to view this content.
    This option requires all variables to be declared and will give a compiler error for undeclared variables.

    Lewis

  3. #3
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,177

    Re: Count Files in a folder and subfolders, with specific name

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    11-10-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    549

    Re: Count Files in a folder and subfolders, with specific name

    @LJMetzger, @ranman256
    Thanks very much, both of these modules work.
    Just with the latter, it includes wildcards.

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Count Files in a folder and subfolders, with specific name

    You don't need a seperate fuction to get activeworkbook name.
    Please Login or Register  to view this content.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] list of subfolders in folder - without files and sub-subfolders
    By MartyZ in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-11-2022, 10:56 AM
  2. Copy specific files from subfolders to new folder
    By dxl in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-28-2016, 06:06 PM
  3. Get Value Function Loop through all files in folder and its subfolders
    By Cheeseburger in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-27-2016, 06:19 PM
  4. VBA that goes through all xls files in folder and subfolders
    By Acxer in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-18-2015, 09:06 AM
  5. VBA to check if any files in folder (and subfolders) are open?
    By Rerock in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-12-2014, 03:48 PM
  6. Moving Files from Folder and Subfolders
    By mvinay in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-30-2014, 01:59 AM
  7. Counting files in folder including subfolders also and folder size
    By mido609 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-12-2012, 03:26 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1