Tested in Excel 365 (16.8730.2046) 64-bit. All links open in new tab.
- Public Sub ListFileProperties()
- ' need to add the following reference:
- ' Microsoft Scripting Runtime
- Dim fso As New FileSystemObject, folder As Variant, file As Variant
- Dim currRow As Long, folderPath As String
- Application.DisplayAlerts = False
- If SheetExists("Files List") Then Sheets("Files List").Delete
- Application.DisplayAlerts = True
- folderPath = PickFileOrFolder(0)
- If folderPath = "" Then Exit Sub
- Set fso = CreateObject("Scripting.FileSystemObject")
- If fso.FolderExists(folderPath) Then
- Set folder = fso.GetFolder(folderPath)
- Else
- MsgBox "Folder doesn't exist!", vbCritical, "Warning"
- Exit Sub
- End If
- Sheets.Add
- Range("A1").Value = "File Name"
- Range("B1").Value = "Creation Date"
- Range("C1").Value = "Modified Date"
- Range("D1").Value = "File Size"
- currRow = 2
- For Each file In folder.Files
- Range("A" & currRow).Value = file.Name
- Range("B" & currRow).Value = file.DateCreated
- Range("C" & currRow).Value = file.DateLastModified
- Range("D" & currRow).Value = file.Size
- currRow = currRow + 1
- Next
- ActiveSheet.Name = "Files List"
- Range("A" & currRow).Value = folderPath
- End Sub
PickFileOrFolder function is here
SheetExists function is here