📊 VBA (Excel)

Clean Up Microsoft Edge's browser cache (VBA)

Deletes every file in Microsoft Edge's browser cache after a confirmation prompt, using Scripting.FileSystemObject from Excel VBA. Locked files are skipped, not fatal.

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

Public Sub EdgeCacheCleanup()
    Dim fso As Object
    Dim folder As Object
    Dim f As Object
    Dim folderPath As String
    Dim deletedCount As Long
    Dim response As VbMsgBoxResult

    folderPath = Environ("LOCALAPPDATA") & "\Microsoft\Edge\User Data\Default\Cache"

    Set fso = CreateObject("Scripting.FileSystemObject")

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

    response = MsgBox("Delete all files in:" & vbCrLf & folderPath & "?", vbYesNo + vbQuestion, "Microsoft Edge's browser cache")
    If response <> vbYes Then Exit Sub

    Set folder = fso.GetFolder(folderPath)
    deletedCount = 0

    For Each f In folder.Files
        On Error Resume Next
        f.Delete True
        If Err.Number = 0 Then deletedCount = deletedCount + 1
        Err.Clear
        On Error GoTo 0
    Next f

    MsgBox deletedCount & " file(s) deleted from " & folderPath, vbInformation
End Sub