Runtime Error 55: “File already open,” explained and fixed

Error 55, “File already open”, means an Open statement targeted a file that this process already has open, or that is still locked from an earlier open that was never closed. Unlike an operating-system sharing violation, error 55 is VBA's own bookkeeping: the same file cannot be opened twice by the same program, even under a different file number. The usual story is a previous run, or an error path, that skipped its Close.

For people who just run the program

  1. Restart the application and run the macro once. If it works after a restart and fails on the second run, the macro is leaving the file open behind it, and the restart is what cleared the lock.
  2. Note whether an earlier run failed partway. A crash or a stopped macro often leaves the file open in the still-running application, blocking the next attempt.
  3. Save your work before restarting. The application holding the file open is the one running the macro; closing it releases the file along with everything else.
  4. Report the pattern, not just the error. “Works once, then fails until I restart” identifies this bug precisely.

For people who write the code

  1. Pair every Open with a Close on all paths, including errors. The standard pattern is an error handler whose cleanup section closes the file if it was opened:
  2. Dim fn As Integer
    On Error GoTo Fail
    fn = FreeFile
    Open path For Input As #fn
    ' ... read ...
    Close #fn
    Exit Sub
    Fail:
        If fn <> 0 Then Close #fn   ' release even when the read failed
        Err.Raise Err.Number
  3. Do not open the same file twice for convenience. Reading a header and a body from one file is one Open with a Seek, not two Opens. If two modes are truly needed, close the first before opening the second.
  4. Hunt for the phantom first open. When error 55 fires on the visibly first Open, something else in the project opened the file earlier: a form load, a class initializer, a previous procedure that returned early. Search for every Open of that path.
Error 55 is not the Windows “file in use” message. Another program holding the file produces different errors (70 or 75). Error 55 specifically means this same process already has it open, so the fix is inside this code, not in closing other applications.

If it still happens

If no second Open exists anywhere, the file may have been opened implicitly: some controls and libraries open their data files and keep them. Test with the suspect control or library removed, and check whether the failure began when it was added.

Common questions

Why does error 55 happen on the second run but not the first? Because the first run left the file open, typically by exiting through an error path that skipped Close. The lock belongs to the application process, so it survives until the application restarts.

Can two different macros conflict this way? Yes. The lock is per process, not per macro. Any code running in the same application instance shares the same open-file table.

Related errors

Runtime Error 54 · Runtime Error 58 · Runtime Error 62