Runtime Error 53: File not found (Dir function failures).

VBA raises Runtime Error 53: File not found when a file-handling command—such as Kill, FileCopy, Name, or a direct file open statement (Open ... For Input)—attempts to access a file that does not exist at the specified path. This error frequently occurs when developers use the Dir() function improperly or make inaccurate assumptions about what Dir() returns.

Quick Answer

Resolve Runtime Error 53 by verifying that the file path and extension are spelled correctly, ensuring all path separators (\) are present, validating that the file exists using If Dir(fullPath) <> "" Then before calling file operations like Kill or FileCopy, and avoiding calling Dir() inside nested routines that overwrite the current directory pointer.


How the Dir Function Causes File Not Found Errors

The Dir() function in VBA returns a string representing the name of a file or folder that matches a specified path or wildcard pattern. If no matching file is found, it returns an empty string ("").

The Dir function itself does not raise Error 53 when a file is missing; it simply returns "". Error 53 happens when code relies on Dir without checking its output, and then passes a blank or invalid path into a file-manipulation statement:

Dim myFile As String
myFile = Dir("C:\Temp\Export_2026.csv")

' If Export_2026.csv does not exist, myFile is "".
' Calling Kill on an empty string or invalid filename triggers Runtime Error 53:
Kill "C:\Temp\" & myFile

The Two Biggest Traps with Dir()

Trap 1: The “Dir Only Returns the Filename” Trap

When Dir("C:\Reports\Sales.xlsx") finds a match, it does not return "C:\Reports\Sales.xlsx". It returns only "Sales.xlsx".

If you later pass that variable into another statement that requires a full path, VBA looks in the current working directory (which may be your Documents folder or OneDrive sync root), not the folder you originally queried:

' BROKEN:
Dim fName As String
fName = Dir("C:\Reports\Daily.xlsx")
If fName <> "" Then
    ' Fails with Error 53 if current directory is not "C:\Reports\":
    FileCopy fName, "D:\Backups\" & fName
End If

' FIXED: Re-attach the directory path:
Dim fFolder As String
fFolder = "C:\Reports\"
fName = Dir(fFolder & "Daily.xlsx")
If fName <> "" Then
    FileCopy fFolder & fName, "D:\Backups\" & fName
End If

Trap 2: Nested Dir() Loops

The Dir() function operates as a single global iterator in VBA. If you start a loop over files in one directory, and inside that loop you call Dir() on a second directory, you reset the state of the first search:

' DANGEROUS: Nested Dir resets the enumeration pointer
f1 = Dir("C:\Folder1\*.txt")
Do While f1 <> ""
    ' This call overwrites the internal state of Dir:
    f2 = Dir("C:\Folder2\*.txt")

    ' This will fail or exit prematurely:
    f1 = Dir()
Loop

The Solution: Use the Scripting.FileSystemObject (FSO) from the Microsoft Scripting Runtime library whenever you need to traverse nested folders or open files reliably without pointer conflicts:

Dim fso As Object
Dim mainFolder As Object, fileObj As Object

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists("C:\Reports\Sales.xlsx") Then
    fso.CopyFile "C:\Reports\Sales.xlsx", "D:\Backups\Sales.xlsx"
Else
    MsgBox "File does not exist.", vbExclamation
End If

For basic path and workbook opening issues, see Runtime Error 1004: “Cannot access the file ‘filename.xlsx'” (Pathing issues)..