📊 VBA (Excel)

List Files in Stuck print spooler files (VBA)

Lists every file in stuck print spooler files with size and last-modified date directly on the active worksheet, using Scripting.FileSystemObject.

By WindowsScripting.com · 1 KB
SpoolerFilesListFiles.bas
Attribute VB_Name = "SpoolerFilesListFiles"
Option Explicit

Public Sub SpoolerFilesListFiles()
    Dim fso As Object
    Dim folder As Object
    Dim f As Object
    Dim folderPath As String
    Dim ws As Worksheet
    Dim r As Long

    folderPath = "C:\Windows\System32\spool\PRINTERS"

    Set fso = CreateObject("Scripting.FileSystemObject")

    If Not fso.FolderExists(folderPath) Then
        MsgBox "Folder not found:" & vbCrLf & folderPath, vbExclamation
        Exit Sub
    End If

    Set ws = ActiveSheet
    ws.Cells.Clear
    ws.Cells(1, 1).Value = "File Name"
    ws.Cells(1, 2).Value = "Size (KB)"
    ws.Cells(1, 3).Value = "Last Modified"
    ws.Rows(1).Font.Bold = True

    Set folder = fso.GetFolder(folderPath)
    r = 2
    For Each f In folder.Files
        ws.Cells(r, 1).Value = f.Name
        ws.Cells(r, 2).Value = Format(f.Size / 1024, "#,##0.0")
        ws.Cells(r, 3).Value = f.DateLastModified
        r = r + 1
    Next f

    ws.Columns.AutoFit
    MsgBox (r - 2) & " file(s) listed from " & folderPath, vbInformation
End Sub