Runtime Error 1004: “Cannot access the file ‘filename.xlsx'” (Pathing issues).

VBA displays Runtime Error 1004: “Cannot access the file ‘filename.xlsx'” when executing commands like Workbooks.Open, .SaveAs, or file export methods if Excel cannot reach or lock the target file path.

Quick Answer

Verify that the file path exists, that the filename and extension are spelled correctly, that the file path does not exceed Windows length limits (260 characters), and that the file is not currently locked by another application or mapped to an unavailable network drive. Use Dir(filePath) to verify file existence prior to calling Workbooks.Open.


Key Causes of File Path Failures

Excel encounters this error when the file system or operating system rejects access to the requested path. The failure typically traces back to one of five causes:

  1. Typographical Errors: A misspelled folder name, missing slash (\), or wrong extension (.xlsx vs .xlsm or .xlsb).
  2. Relative Path Assumptions: Assuming the working directory is ThisWorkbook.Path when Excel’s default directory points elsewhere.
  3. OneDrive / SharePoint URL Confusion: Modern Office setups often resolve local paths to cloud URLs (https://...), which Workbooks.Open cannot always parse identically to local paths.
  4. File Locking and Ghost Files: Another process has an exclusive write lock on the target file.
  5. Path Length Limits: Total character length of the path and filename exceeds standard operating system limits.

Systematic Troubleshooting Steps

Step 1: Pre-Validate File Existence with Dir()

Never run Workbooks.Open directly on a raw string variable without checking whether the operating system can see it:

Sub OpenTargetWorkbook()
    Dim targetPath As String
    targetPath = "C:\Reports\2026\Summary.xlsx"

    ' Check if file exists before opening
    If Dir(targetPath) = "" Then
        MsgBox "File not found at: " & vbCrLf & targetPath, vbCritical, "Path Error"
        Exit Sub
    End If

    Dim wb As Workbook
    Set wb = Workbooks.Open(targetPath)
End Sub

If Dir(targetPath) returns an empty string "", the path string is inaccurate or inaccessible under your current Windows credentials.

Step 2: Handle OneDrive and SharePoint Synchronized Paths

If your workbooks are synchronized with OneDrive or SharePoint, ThisWorkbook.Path may return an HTTP URL instead of a drive letter path:

  • Local Path: C:\Users\Username\Company\Folder\file.xlsx
  • URL Path: https://company.sharepoint.com/teams/Folder/file.xlsx

Passing an HTTP path with spaces or encoded characters (like %20) can cause Workbooks.Open to trigger Error 1004. If you run macros across cloud-backed directories, consult Fixing VBA errors caused by “OneDrive” autosave and temp file paths. for methods to translate cloud URLs to physical drive paths.

Step 3: Check for Hidden Lock Files

If a file crashes or terminates improperly, Excel leaves behind a hidden lock file in the same directory (named ~$filename.xlsx).

  • Open Windows File Explorer.
  • Turn on Hidden items under the View tab.
  • Look for files beginning with ~$. Delete any abandoned lock files for workbooks that are not currently running.

If dealing with shared folders or network locks, see “The file is locked for editing”: How to kill “Ghost” owner files (~$filename). and Runtime Error 1004: “The file could not be accessed” (Network drive timeouts)..

Step 4: Correct Path Concatenation Syntax

A missing backslash between the folder and filename is one of the most common syntax issues:

' Wrong: Results in "C:\ReportsSummary.xlsx"
filePath = folderPath & fileName

' Correct:
If Right(folderPath, 1) <> Application.PathSeparator Then
    folderPath = folderPath & Application.PathSeparator
End If
filePath = folderPath & fileName