Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel VBA: List All File Properties

· 6 min read · Home Tech

In this article
  1. Why You'd Want to List File Properties
  2. Method 1: FileSystemObject (Basic Properties)
  3. Method 2: Shell.Application (Extended Properties)
  4. Choosing the Right Method
  5. Common Problems and How to Fix Them
  6. Alternatives to VBA
  7. Frequently Asked Questions

To list all file properties in Excel VBA, you can use the FileSystemObject to retrieve basic attributes (name, size, date created, date last modified, date last accessed) or the Shell.Application object to access extended properties (author, title, comments, etc.). This article explains both methods, provides step-by-step code, and covers common pitfalls so you can extract exactly the metadata you need.

Why You'd Want to List File Properties

File properties—also called metadata—are the behind-the-scenes details stored with every file. They include the obvious (file name, size, type) and the less obvious (date created, date last modified, author, title, keywords, and even camera model for photos). In Excel VBA, pulling these into a worksheet is useful for:

  • Building an inventory of files in a folder or drive
  • Auditing documents for compliance or record-keeping
  • Identifying large files or old files for cleanup
  • Extracting author or title information from a batch of documents

Excel itself stores properties for its own workbooks (accessible via Workbook.BuiltinDocumentProperties), but that only works for files currently open. To list properties of any file—Excel, Word, PDF, image, or otherwise—you need a more general approach.

Method 1: FileSystemObject (Basic Properties)

The FileSystemObject (FSO) is part of Microsoft Scripting Runtime, which is built into Windows. It's the simplest way to get the most commonly needed file attributes. To use it, you must first enable the reference in the VBA editor: go to Tools > References and check Microsoft Scripting Runtime.

The FSO File object exposes these properties:

  • Name – file name including extension
  • Path – full path
  • Size – bytes (divide by 1024 for KB, 1048576 for MB)
  • Type – file type description (e.g., "Microsoft Excel Worksheet")
  • DateCreated – creation date/time
  • DateLastModified – last save date/time
  • DateLastAccessed – last open date/time
  • Attributes – numeric code for read-only, hidden, system, etc.

Here's a macro that lists these properties for every file in a chosen folder:

Sub ListBasicProperties()
    Dim fso As Object, folder As Object, file As Object
    Dim ws As Worksheet, r As Long
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set folder = fso.GetFolder("C:\\YourFolderPath")
    Set ws = ThisWorkbook.Sheets(1)
    
    ws.Cells.Clear
    ws.Range("A1:G1") = Array("Name", "Path", "Size (KB)", "Type", "Created", "Modified", "Accessed")
    r = 2
    For Each file In folder.Files
        ws.Cells(r, 1) = file.Name
        ws.Cells(r, 2) = file.Path
        ws.Cells(r, 3) = Round(file.Size / 1024, 2)
        ws.Cells(r, 4) = file.Type
        ws.Cells(r, 5) = file.DateCreated
        ws.Cells(r, 6) = file.DateLastModified
        ws.Cells(r, 7) = file.DateLastAccessed
        r = r + 1
    Next file
    ws.Columns.AutoFit
End Sub

Note that DateLastAccessed may not always be accurate on modern NTFS volumes because Windows disables last-access updates by default for performance.

Method 2: Shell.Application (Extended Properties)

For properties like Author, Title, Comments, or camera model, FSO isn't enough. These are stored in the file's property store, which Windows Explorer shows in the Details tab. You can access them through the Shell.Application object. This method works without any additional references.

The key is to use Shell.Namespace for the folder and Namespace.GetDetailsOf for each file. The second argument is a zero-based index that corresponds to a property column. For example, index 0 is Name, index 1 is Size, index 2 is Item type, and so on. The indices vary by Windows version and file type, but common ones are:

  • 0 – Name
  • 1 – Size
  • 2 – Item type
  • 3 – Date modified
  • 4 – Date created
  • 5 – Date accessed
  • 6 – Attributes
  • 9 – Author
  • 10 – Title
  • 11 – Subject
  • 12 – Category
  • 13 – Comments

Here's a macro that lists extended properties for all files in a folder, using a loop to fetch every available property index (0 to 300) and writing only non-empty ones:

Sub ListExtendedProperties()
    Dim shell As Object, folder As Object, file As Object
    Dim ws As Worksheet, r As Long, i As Long
    Dim folderPath As String
    
    folderPath = "C:\\YourFolderPath"
    Set shell = CreateObject("Shell.Application")
    Set folder = shell.Namespace(folderPath)
    Set ws = ThisWorkbook.Sheets(1)
    
    ws.Cells.Clear
    ws.Cells(1, 1) = "File"
    r = 2
    For Each file In folder.Items
        ws.Cells(r, 1) = folder.GetDetailsOf(file, 0)
        For i = 1 To 300
            Dim propName As String, propValue As String
            propName = folder.GetDetailsOf(vbNullString, i)
            propValue = folder.GetDetailsOf(file, i)
            If propName <> "" And propValue <> "" Then
                ws.Cells(1, i + 1) = propName
                ws.Cells(r, i + 1) = propValue
            End If
        Next i
        r = r + 1
    Next file
    ws.Columns.AutoFit
End Sub

This code writes property names in row 1 and values in subsequent rows. It's slower than FSO because it iterates up to 300 properties per file, but it captures everything Explorer shows.

Choosing the Right Method

Which one you use depends on what you need:

  • Basic attributes only (size, dates, type) – use FileSystemObject. It's faster, simpler, and doesn't require looping through hundreds of indices.
  • Author, title, comments, or other extended metadata – use Shell.Application. It's the only built-in way to get these without third-party libraries.
  • Both – combine the two: use FSO for speed on basic fields and Shell for the extended ones.

Also consider that FSO requires the scripting runtime reference, which is available on all Windows systems but may need to be enabled in the VBA editor. Shell.Application needs no reference but is slower and the property indices are not officially documented, so they can change.

Common Problems and How to Fix Them

Here are the typical issues you'll run into:

  • "User-defined type not defined" – You didn't add the Microsoft Scripting Runtime reference. Either add it or declare all FSO variables as Object (as shown above).
  • Permission denied – The file is locked by another process (e.g., open in Word). Use error handling to skip it.
  • Empty extended properties – Many files simply don't have author or title set. The Shell method returns an empty string, which is normal.
  • Wrong property index – If you're getting unexpected values (like file size in the Author column), the index mapping differs on your system. Use the loop method to discover the correct indices.
  • Slow performance on large folders – Shell.Application is notoriously slow. Limit the number of files or use FSO for basic fields first.

Alternatives to VBA

If you're not tied to Excel, consider these alternatives:

  • PowerShell – Get-ChildItem | Select-Object Name, Length, LastWriteTime gives basic properties instantly. For extended ones, use Get-Item with the VersionInfo property.
  • Windows Explorer – Add columns via right-click on the column header. This works for a one-off view but not for automation.
  • Command Prompt – dir /T:C shows creation time, /T:W for last write, /T:A for last access.
  • Third-party metadata tools – ExifTool is a popular command-line utility for reading/writing metadata, but it requires installation.

Frequently Asked Questions

Can I list properties of files in subfolders recursively?

Yes, but you need to loop through subfolders. For FSO, use a recursive procedure that calls itself for each subfolder. For Shell.Application, the Items collection only includes the current folder, so you'd need to call Namespace for each subfolder separately. Alternatively, use PowerShell's -Recurse flag for a one-liner solution.

How do I get the file owner or permissions?

FSO and Shell.Application don't expose owner or ACL information. You'd need to use WMI (Win32_LogicalFileSecuritySetting) or a Windows API call. This is more advanced and requires additional code, but it's possible.

Why does the DateLastAccessed property show a date from years ago?

Windows disables last-access time updates on NTFS by default to improve performance. You can enable it via fsutil behavior set disablelastaccess 0 in an elevated command prompt, but it's not recommended for routine use.

Can I list properties of files that are open in other programs?

Yes, but you may get a "Permission denied" error when trying to read the file. Wrap your file access in an error handler and skip files that can't be read. The property store is usually accessible even when the file is locked.

Is there a way to list all properties without knowing the index numbers?

Yes, the loop method shown above (iterating 0 to 300) discovers all available properties dynamically. It's slower but foolproof. You can also store the property names in an array once and reuse it for all files.