+ Reply to Thread
Results 1 to 10 of 10

List All SubFolders In A Folder Excel 2013

  1. #1
    Forum Contributor PY_'s Avatar
    Join Date
    09-23-2008
    Location
    Houston
    MS-Off Ver
    Office 2016
    Posts
    289

    List All SubFolders In A Folder Excel 2013

    I am having the hardest time searching for a macro that will list all folders and subfolders using VB. Does anyone have one that will work with Excel 2013? If i had a choice, i would like all folders to be listed in column A of Sheet1. So sub folders would not slide to the next column, they will just remain under column A.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: List All SubFolders In A Folder Excel 2013

    Hi PV

    This works in Excel 2010...don't have 2013
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Forum Contributor PY_'s Avatar
    Join Date
    09-23-2008
    Location
    Houston
    MS-Off Ver
    Office 2016
    Posts
    289

    Re: List All SubFolders In A Folder Excel 2013

    That is close! I will see if i can modify it to fit my needs. Do you know how to modify it so it only lists Folder names? If it can remove the folder paths that would be even better.

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: List All SubFolders In A Folder Excel 2013

    Hi PV

    Try changing this line of Code
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor PY_'s Avatar
    Join Date
    09-23-2008
    Location
    Houston
    MS-Off Ver
    Office 2016
    Posts
    289

    Re: List All SubFolders In A Folder Excel 2013

    No that is still listing the files and multiple lines per folder.

    I'm looking for a result similar to this if i ran it for C:\

    All of this will be in a single column A:
    Program Files
    Sub Folder(s) of Program Files
    Sub Folder(s) of each Sub Folder Inside Program Files
    Sub Folder(s) of each Sub Folder of......etc
    Windows
    Sub Folder(s) of Windows
    Sub Folder(s) of each Sub Folder Inside Windows
    Sub Folder(s) of each Sub Folder of......etc
    Etc...etc...
    Last edited by PY_; 07-17-2013 at 10:06 PM.

  6. #6
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: List All SubFolders In A Folder Excel 2013

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor PY_'s Avatar
    Join Date
    09-23-2008
    Location
    Houston
    MS-Off Ver
    Office 2016
    Posts
    289

    Re: List All SubFolders In A Folder Excel 2013

    That works!
    Is it possible to NOT show the subfolder information to the left so it only shows the folder name and not the path?

    I was able to display just the folder name using this code in B1 copied down but if it can be done using vba, that would be less coding on the worksheet.

    =TRIM(RIGHT(SUBSTITUTE(A1,"\",REPT(" ",LEN(A1))),LEN(A1)))

  8. #8
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: List All SubFolders In A Folder Excel 2013

    Hi PY_,

    Try this:

    Please Login or Register  to view this content.
    HTH

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  9. #9
    Forum Contributor PY_'s Avatar
    Join Date
    09-23-2008
    Location
    Houston
    MS-Off Ver
    Office 2016
    Posts
    289

    Re: List All SubFolders In A Folder Excel 2013

    Robert, that worked great. I did tweak it a little because for me, i did not need the paths in A, just the names from B. Here is my final code and thanks again!

    Please Login or Register  to view this content.

  10. #10
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: List All SubFolders In A Folder Excel 2013

    PY. Your Clear.Cells should be Cells.Clear. I am not sure why you deleted Column B. I think that you meant column A.

    Please note that this DIR method may translate characters. e.g. The Daily Dose of Excel website page when saved in the browser creates a folder name with some characters like >>. These are translated by this method into an upperscore character. While you may not ever see that, I wanted to note it for others.

    It appears that folders like this:
    x:\a
    x:\a\b
    x:\a\b\a
    would become
    a
    b
    a.

    If that is what you wanted, the last subfolder name, I would parse the last subfolder name into in an array. Normally, I would use an FSO method but that method fails for the scenario noted.

    Please Login or Register  to view this content.
    I recently helped a poster do something similar though they just want the folders in a parent folder. I put those folder names into a Data Validation dropdown list. For that scenario, fso, or DIR() methods suffice.
    Last edited by Kenneth Hobson; 07-18-2013 at 10:10 AM.

+ 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. Macro to create hyperlink list of every file in a folder, subfolders, and SHORTCUTS
    By Billdick7788 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-20-2013, 11:11 AM
  3. [SOLVED] Insert Picture to excel from subfolders and save as folder name
    By gincemathew in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 02-14-2013, 10:01 AM
  4. [SOLVED] Opening Excel files in same folder through a Macro - but not subfolders?
    By toffee_madman in forum Excel General
    Replies: 9
    Last Post: 10-19-2011, 11:09 AM
  5. Replies: 2
    Last Post: 05-07-2006, 03:20 PM

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