• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Macro to count folders and sub-folders with .pdf file counts

Bricklin

New Member
Need some help with a macro to count all the sub-folders within a folder and then all the total files within all the sub-folders. I'd like to have the results displayed on a sheet within a workbook.

Folder name is "C:/Quotes Tool" - Need a count of all the sub-folders in this folder

Total Quotes = need count of all the .pdf files within the folder and sub-folders under C:\Quotes Tool (don't need it broken out by sub-folder - just the total amount of .pdf files.

Would like to display it like this on a sheet like "You have created xxx (number of pdf files) total quotes for xxx (number of sub-folders)."

I reviewed some similar requests but was unable to adapt them to work as above.

Thanks
 
This code to count sub-folders.
Code:
Sub FolderCount()
    Dim FSO As Object
    Dim folder As Object
    Dim subfolders As Object
  
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set folder = FSO.GetFolder("C:\Quotes Tool\")
    Set subfolders = folder.subfolders
    MsgBox subfolders.Count
  
    Set FSO = Nothing
    Set folder = Nothing
    Set subfolders = Nothing
  
End Sub

And use code in link to count PDF in sub-folders (You can use bogus name for exclusion portion. IE. Replace "Entered" with "Folder Name that Doesn't exist").
http://stackoverflow.com/questions/...r-and-subfolders-exlucing-folders-with-string

FYI - Make sure user(s) have appropriate permissions for folders or it will spit out error.
 
Great!

I have both working.

For the count of the folders, how would a save the count to a specific cell instead of displaying it in the message box?

example if the count was 68, I'd like to have the sheet named "Input" in cell AC115 show 68.

I appreciate your help.
 
In that case, replace MsgBox portion with following.
Code:
ActiveWorkbook.Sheets("Input").Range("AC115") = subfolders.Count
 
Back
Top