List Folders & Subfolders From Directory

  • Does anyone know how to list all the folders/subfolders (no files) of a specified directory?
    I've seen a few examples of listing filenames from directories but I'm unsure how to just list folders/subfolders.


    Brad

    Brad.

  • Re: List Folders & Subfolders From Directory


    Hi Brad,


    Found a few on the net. Googled "vba list folders subfolders".


    Each one requires a reference to the "Microsoft Scripting Library". In the VBE I choose Tools/References and clicked "Microsoft Scripting Runtime".


    Then run this code. The original had the "Debug.Print line, I changed it to print on the sheet...


    The two best places I found were:


    http://www.vbforums.com/showthread.php?s=&threadid=244880


    This one I had to reformat all of the code after I copied/pasted it. It came out as one LONG line...



    This looks good too:


    http://www.erlandsendata.no/en…lderslistfoldersscripting


    A better explanation, different code.


    Here's the first, edited:



    and the second


  • Re: List Folders & Subfolders From Directory


    Place this code in a Standard module



    In a second Module copy this code



    NOTE: This code uses Microsoft Scripting Runtime. The macro examples need a reference to the Microsoft Scripting Runtime library. You can do this from within the VBE by selecting the menu Tools > References and scroll for Microsoft Scripting Runtime, check th box then click OK

  • Re: List Folders & Subfolders From Directory


    Thanks Guys,


    Quote from royUK

    NOTE: This code uses Microsoft Scripting Runtime. The macro examples need a reference to the Microsoft Scripting Runtime library. You can do this from within the VBE by selecting the menu Tools > References and scroll for Microsoft Scripting Runtime, check th box then click OK


    Does this mean the user that I send this spreadsheet to will need to have Microsoft Scripting Runtime checked in the VBE also?


    Brad

    Brad.

  • Re: List Folders & Subfolders From Directory


    Please help, why this not working in excel 2007. I cant even seed where the settings is to be done.

  • Re: List Folders & Subfolders From Directory


    Ped,


    DO NOT resurrect old threads, or hijack any other thread. Start your own thread and, if it helps clarify your own needs, provide a link back to this thread.
    Please take the time to read the Forum Rules and follow them. This is second infraction in two days. If you want to continue posting, then take the time to understand the rules you agreed to abide by when you subscribed to this forum.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!