How Do I Get a List of All Folders and Subfolders in Excel?
![]() |
Have you ever wished there was an easy button to get a list of all your folders and sub-folders, complete with their paths, names, creation dates, and when they were last changed, all neatly organized in a spreadsheet?
We know it's not usually a quick and simple task to get all that information at once. But good news! This post will walk you through a clever way to do just that. You'll learn how to get all those details from a specific directory right into a workbook.
Just follow the step-by-step guide below. I found this really effective workaround from ExtendOffice, and I'm excited to share it with you!
1. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following VBA code: List all folders and subfolder paths and names into the Module Window.
Sub FolderNames() 'Update 20141027 Application.ScreenUpdating = False Dim xPath As String Dim xWs As Worksheet Dim fso As Object, j As Long, folder1 As Object With Application.FileDialog(msoFileDialogFolderPicker) .Title = "Choose the folder" .Show End With On Error Resume Next xPath = Application.FileDialog(msoFileDialogFolderPicker).SelectedItems(1) & "\" Application.Workbooks.Add Set xWs = Application.ActiveSheet xWs.Cells(1, 1).Value = xPath xWs.Cells(2, 1).Resize(1, 5).Value = Array("Path", "Dir", "Name", "Date Created", "Date Last Modified") Set fso = CreateObject("Scripting.FileSystemObject") Set folder1 = fso.getFolder(xPath) getSubFolder folder1 xWs.Cells(2, 1).Resize(1, 5).Interior.Color = 65535 xWs.Cells(2, 1).Resize(1, 5).EntireColumn.AutoFit Application.ScreenUpdating = True End Sub Sub getSubFolder(ByRef prntfld As Object) Dim SubFolder As Object Dim subfld As Object Dim xRow As Long For Each SubFolder In prntfld.SubFolders xRow = Range("A1").End(xlDown).Row + 1 Cells(xRow, 1).Resize(1, 5).Value = Array(SubFolder.Path, Left(SubFolder.Path, InStrRev(SubFolder.Path, "\")), SubFolder.Name, SubFolder.DateCreated, SubFolder.DateLastModified) Next SubFolder For Each subfld In prntfld.SubFolders getSubFolder subfld Next subfld End Sub
3. Now press the F5 key to run the VB Code, a window will pop out and choose FolderNames and click Run. A new window will pop out again to choose the folder/directory you want to list the folder and subfolder names.
4. Click OK, and you will get the folder and sub-folders paths, directories, names, created dates and last modified dates in a new workbook.
The time your report will be shown on a new workbook depends on the volume of folders and sub-folders. Mine took less than 30 minutes because it has thousands of folders. The lesser folders the faster the report will be extracted.