📁 Create File Index with Excel VBA
Want to catalog all files in any folder—automatically—in Excel? This VBA tool lists file details like name, path, size, and dates into a spreadsheet. Let's automate it!
🧰 Features
- Select any folder with one click
- Include subfolders optionally
- Display: name, path, extension, size, modified & created dates
- Support for all file types
- Clean and simple Excel layout
💾 VBA Code
Click the button below to copy the entire code:
Sub CreateFileIndex() Dim ws As Worksheet Dim folderPath As String, filePath As String Dim fso As Object, folder As Object, subFolder As Object, file As Object Dim rowIndex As Long Dim includeSubfolders As VbMsgBoxResult With Application.FileDialog(msoFileDialogFolderPicker) .Title = "Select Folder to Index" If .Show <> -1 Then Exit Sub folderPath = .SelectedItems(1) End With includeSubfolders = MsgBox("Include subfolders?", vbYesNo + vbQuestion, "Subfolder Option") Set ws = ThisWorkbook.Sheets(1) ws.Cells.Clear ws.Range("A1:F1").Value = Array("File Name", "Path", "Size (KB)", "Last Modified", "Extension", "Created Date") rowIndex = 2 Set fso = CreateObject("Scripting.FileSystemObject") If includeSubfolders = vbYes Then Call ListFilesRecursive(fso.GetFolder(folderPath), ws, rowIndex) Else Set folder = fso.GetFolder(folderPath) For Each file In folder.Files ws.Cells(rowIndex, 1).Value = file.Name ws.Cells(rowIndex, 2).Value = file.Path ws.Cells(rowIndex, 3).Value = Round(file.Size / 1024, 2) ws.Cells(rowIndex, 4).Value = file.DateLastModified ws.Cells(rowIndex, 5).Value = fso.GetExtensionName(file.Name) ws.Cells(rowIndex, 6).Value = file.DateCreated rowIndex = rowIndex + 1 Next file End If MsgBox "Indexing complete!", vbInformation End Sub Sub ListFilesRecursive(folder As Object, ws As Worksheet, ByRef rowIndex As Long) Dim file As Object, subFolder As Object For Each file In folder.Files ws.Cells(rowIndex, 1).Value = file.Name ws.Cells(rowIndex, 2).Value = file.Path ws.Cells(rowIndex, 3).Value = Round(file.Size / 1024, 2) ws.Cells(rowIndex, 4).Value = file.DateLastModified ws.Cells(rowIndex, 5).Value = Right(file.Name, Len(file.Name) - InStrRev(file.Name, ".")) ws.Cells(rowIndex, 6).Value = file.DateCreated rowIndex = rowIndex + 1 Next file For Each subFolder In folder.SubFolders ListFilesRecursive subFolder, ws, rowIndex Next subFolder End Sub
📬 Contact Us for Customizations
Need a version with filters, timestamped saving, or formatting? Reach out below!
0 Comments