{"id":4768,"date":"2016-11-19T00:17:30","date_gmt":"2016-11-19T00:17:30","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/wp\/?p=4768"},"modified":"2016-11-19T00:17:30","modified_gmt":"2016-11-19T00:17:30","slug":"list-folders-and-subfolders-in-excel","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/","title":{"rendered":"List all Folders and Sub-folders in Hierarchical Structure [FREE DOWNLOAD]"},"content":{"rendered":"

Dear Readers,<\/p>\n

Many of you were looking for a excel tool same as File Manager – which lists down all the files from each and every folders and subfolders,<\/a><\/strong> to list down all the folders and sub-folders under a given Main Folder Path. Therefore rather than replying to you all individually a piece of code, I though of posting an article with a downloadable file which can be used to list all folders and subfolders in your excel sheet in a Hierarchical structure <\/strong> (same as the folders and sub-folders are structured).
\n

\"List<\/a>

List Folders and Sub Folders<\/p><\/div><\/p>\n

VBA Code to list All the Folders and Sub Folders inside a given Main Folder Path<\/h2>\n
\r\nSub ListAllFoldersAndSubFolders(SourceFolderName As String, isSubFolder As Boolean)\r\n\r\n'--- For Example:Folder Name= \"C:\\Folder Name\\\" and IsSubfolder Flag as True or false\r\n\r\nDim FSO As Scripting.FileSystemObject\r\nDim SourceFolder As Scripting.folder, SubFolder As Scripting.folder\r\nDim FileItem As Scripting.File\r\n\r\nOn Error GoTo err\r\n    \r\n    Set FSO = New Scripting.FileSystemObject\r\n    Set SourceFolder = FSO.GetFolder(SourceFolderName)\r\n\r\n        For Each SubFolder In SourceFolder.Subfolders\r\n            Cells(strtRow, strtCol).Value = SubFolder.Name\r\n            strtRow = strtRow + 1\r\n            If isSubFolder = True Then\r\n                strtCol = strtCol + 1\r\n                ListAllFoldersAndSubFolders SubFolder.Path, isSubFolder\r\n            End If\r\n        Next SubFolder\r\n        ' At the end of the subfolder\r\n        ' set the column back to the\r\n        ' immediate main folder backward\r\n        strtCol = strtCol - 1\r\nerr:\r\n If err.Number <> 0 Then MsgBox err.Description\r\nEnd Sub\r\n<\/code><\/pre>\n

How to call above function or How to use above <\/h2>\n

As you can see to run above function it requires certain parameter like Main Folder Path and a Boolean flag to say if you want to list all subfolders as well or just the folders which are there under the main folder.
\nTherefore you need to call this function as shown in the below example:<\/p>\n

\r\nPublic strtRow As Integer\r\nPublic strtCol As Integer\r\nSub CallAboveFunction()\r\n    'set the start row and column for displaying the list\r\n    strtRow = 2\r\n    strtCol = 2\r\n    ListAllFoldersAndSubFolders \"C:\\Users\\vmishra\\Documents\\Davinci\\VISHWA\", False\r\nEnd Sub\r\n<\/code><\/pre>\n

FREE Download <\/h2>\n

Using the above functions and with some formatting, I have created a simple excel tool where you can list all your folders and sub-folders in a hierarchical structure. You can download this file, use it, refer to the code, share it with friends to help. In short you can do anything you want with this excel :D.<\/p>\n


\n\"Download
\n<\/a> <\/p>\n<\/span>","protected":false},"excerpt":{"rendered":"

Dear Readers, Many of you were looking for a excel tool same as File Manager – which lists down all the files from each and every folders and subfolders, to list down all the folders and sub-folders under a given Main Folder Path. Therefore rather than replying to you all individually a piece of code, […]<\/p>\n","protected":false},"author":45,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1246,1675],"tags":[],"class_list":["post-4768","post","type-post","status-publish","format-standard","hentry","category-macro","category-excel-macro-for-beginners"],"yoast_head":"\nList all Folders and Sub-folders in Hierarchical Structure [FREE DOWNLOAD] - Let's excel in Excel<\/title>\n<meta name=\"description\" content=\"Download free excel tool to list all the folders and sub folders in excel. How to list folders and sub-folders in excel using excel vba. Macro to list folders and sub-folders\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"List all Folders and Sub-folders in Hierarchical Structure [FREE DOWNLOAD]\" \/>\n<meta property=\"og:description\" content=\"Download free excel tool to list all the folders and sub folders in excel. How to list folders and sub-folders in excel using excel vba. Macro to list folders and sub-folders\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/\" \/>\n<meta property=\"og:site_name\" content=\"Let's excel in Excel\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/www.facebook.com\/vmlogger\" \/>\n<meta property=\"article:author\" content=\"http:\/\/www.facebook.com\/vmlogger\" \/>\n<meta property=\"article:published_time\" content=\"2016-11-19T00:17:30+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/learnexcelmacro.com\/wp\/wp-content\/uploads\/sites\/11\/2016\/11\/FoldersAndSubFoldersListing.png\" \/>\n<meta name=\"author\" content=\"Vishwamitra Mishra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/www.twitter.com\/learnexcelmacro\" \/>\n<meta name=\"twitter:site\" content=\"@learnexcelmacro\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vishwamitra Mishra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/\"},\"author\":{\"name\":\"Vishwamitra Mishra\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"headline\":\"List all Folders and Sub-folders in Hierarchical Structure [FREE DOWNLOAD]\",\"datePublished\":\"2016-11-19T00:17:30+00:00\",\"dateModified\":\"2016-11-19T00:17:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/\"},\"wordCount\":253,\"commentCount\":6,\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"image\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2016\/11\/FoldersAndSubFoldersListing.png\",\"articleSection\":[\"Excel Macro\",\"Excel Macro Tutorial\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/\",\"name\":\"List all Folders and Sub-folders in Hierarchical Structure [FREE DOWNLOAD] - Let's excel in Excel\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2016\/11\/FoldersAndSubFoldersListing.png\",\"datePublished\":\"2016-11-19T00:17:30+00:00\",\"dateModified\":\"2016-11-19T00:17:30+00:00\",\"description\":\"Download free excel tool to list all the folders and sub folders in excel. How to list folders and sub-folders in excel using excel vba. Macro to list folders and sub-folders\",\"breadcrumb\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/#primaryimage\",\"url\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2016\/11\/FoldersAndSubFoldersListing.png\",\"contentUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2016\/11\/FoldersAndSubFoldersListing.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/vmlogger.com\/excel\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Excel Macro\",\"item\":\"https:\/\/vmlogger.com\/excel\/macro\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"List all Folders and Sub-folders in Hierarchical Structure [FREE DOWNLOAD]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\",\"url\":\"https:\/\/vmlogger.com\/excel\/\",\"name\":\"Let's excel in Excel\",\"description\":\"Let's share knowledge\",\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/vmlogger.com\/excel\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\",\"name\":\"Vishwamitra Mishra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png\",\"contentUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png\",\"width\":528,\"height\":560,\"caption\":\"Vishwamitra Mishra\"},\"logo\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/\"},\"description\":\"My name is Vishwamitra Mishra. Friends Call me Vishwa. I hold a Bachelor\u2019s Degree in Computer Science from D.A.V.V. Indore & currently working as a Technical Lead having over 7 years of experience.\",\"sameAs\":[\"http:\/\/www.learnexcelmacro.com\",\"http:\/\/www.facebook.com\/vmlogger\",\"https:\/\/x.com\/https:\/\/www.twitter.com\/learnexcelmacro\",\"https:\/\/www.youtube.com\/c\/VMLogger\"],\"url\":\"https:\/\/vmlogger.com\/excel\/author\/vishwamitra\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"List all Folders and Sub-folders in Hierarchical Structure [FREE DOWNLOAD] - Let's excel in Excel","description":"Download free excel tool to list all the folders and sub folders in excel. How to list folders and sub-folders in excel using excel vba. Macro to list folders and sub-folders","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/","og_locale":"en_US","og_type":"article","og_title":"List all Folders and Sub-folders in Hierarchical Structure [FREE DOWNLOAD]","og_description":"Download free excel tool to list all the folders and sub folders in excel. How to list folders and sub-folders in excel using excel vba. Macro to list folders and sub-folders","og_url":"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/","og_site_name":"Let's excel in Excel","article_publisher":"http:\/\/www.facebook.com\/vmlogger","article_author":"http:\/\/www.facebook.com\/vmlogger","article_published_time":"2016-11-19T00:17:30+00:00","og_image":[{"url":"http:\/\/learnexcelmacro.com\/wp\/wp-content\/uploads\/sites\/11\/2016\/11\/FoldersAndSubFoldersListing.png"}],"author":"Vishwamitra Mishra","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/www.twitter.com\/learnexcelmacro","twitter_site":"@learnexcelmacro","twitter_misc":{"Written by":"Vishwamitra Mishra","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/#article","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/"},"author":{"name":"Vishwamitra Mishra","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"headline":"List all Folders and Sub-folders in Hierarchical Structure [FREE DOWNLOAD]","datePublished":"2016-11-19T00:17:30+00:00","dateModified":"2016-11-19T00:17:30+00:00","mainEntityOfPage":{"@id":"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/"},"wordCount":253,"commentCount":6,"publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"image":{"@id":"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/#primaryimage"},"thumbnailUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2016\/11\/FoldersAndSubFoldersListing.png","articleSection":["Excel Macro","Excel Macro Tutorial"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/","url":"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/","name":"List all Folders and Sub-folders in Hierarchical Structure [FREE DOWNLOAD] - Let's excel in Excel","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/#website"},"primaryImageOfPage":{"@id":"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/#primaryimage"},"image":{"@id":"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/#primaryimage"},"thumbnailUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2016\/11\/FoldersAndSubFoldersListing.png","datePublished":"2016-11-19T00:17:30+00:00","dateModified":"2016-11-19T00:17:30+00:00","description":"Download free excel tool to list all the folders and sub folders in excel. How to list folders and sub-folders in excel using excel vba. Macro to list folders and sub-folders","breadcrumb":{"@id":"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/#primaryimage","url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2016\/11\/FoldersAndSubFoldersListing.png","contentUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2016\/11\/FoldersAndSubFoldersListing.png"},{"@type":"BreadcrumbList","@id":"https:\/\/vmlogger.com\/excel\/2016\/11\/list-folders-and-subfolders-in-excel\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vmlogger.com\/excel\/"},{"@type":"ListItem","position":2,"name":"Excel Macro","item":"https:\/\/vmlogger.com\/excel\/macro\/"},{"@type":"ListItem","position":3,"name":"List all Folders and Sub-folders in Hierarchical Structure [FREE DOWNLOAD]"}]},{"@type":"WebSite","@id":"https:\/\/vmlogger.com\/excel\/#website","url":"https:\/\/vmlogger.com\/excel\/","name":"Let's excel in Excel","description":"Let's share knowledge","publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vmlogger.com\/excel\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5","name":"Vishwamitra Mishra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/","url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png","contentUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png","width":528,"height":560,"caption":"Vishwamitra Mishra"},"logo":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/"},"description":"My name is Vishwamitra Mishra. Friends Call me Vishwa. I hold a Bachelor\u2019s Degree in Computer Science from D.A.V.V. Indore & currently working as a Technical Lead having over 7 years of experience.","sameAs":["http:\/\/www.learnexcelmacro.com","http:\/\/www.facebook.com\/vmlogger","https:\/\/x.com\/https:\/\/www.twitter.com\/learnexcelmacro","https:\/\/www.youtube.com\/c\/VMLogger"],"url":"https:\/\/vmlogger.com\/excel\/author\/vishwamitra\/"}]}},"_links":{"self":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/4768"}],"collection":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/users\/45"}],"replies":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/comments?post=4768"}],"version-history":[{"count":0,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/4768\/revisions"}],"wp:attachment":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/media?parent=4768"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/categories?post=4768"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/tags?post=4768"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}