🚀The world's best VBA AI has evolved. ExcelMaster is now an autonomous Agent.Read more →
Back to Blog

VBA Copy File in Excel — FileCopy, FileSystemObject.CopyFile, and Why It Cannot Copy an Open Workbook

|

VBA Copy File in Excel — FileCopy, FileSystemObject.CopyFile, and Why It Cannot Copy an Open Workbook

TL;DRFileCopy source, destination copies a file in one line, needs no references, and silently overwrites whatever is already at the destination. The catch that trips everyone: it cannot copy a file that is open — including the workbook you are running the macro from. Both paths must be complete, file name and all, and the destination folder must already exist:

Sub BackupReport()
    ' Both arguments are FULL paths, including the file name on each side
    FileCopy "C:\Reports\March.xlsx", "C:\Backup\March.xlsx"   ' overwrites Backup silently
End Sub

Once a macro has found the files it needs to work on, the next thing it usually does is act on them — and the gentlest of those actions is to copy one somewhere safe before anything else touches it. That is also where beginners hit their first wall: FileCopy works perfectly on a closed file and then fails with error 70 the moment you point it at a workbook that is open. Understand why, and you will always reach for the right one of the three copy tools.

What you'll learn

  • The mental model — which copy tool you need depends on whether the file is open
  • Why FileCopy overwrites without warning — the opposite of the Name statement
  • Why FileCopy fails with error 70 on an open workbook, and what to use instead
  • Why both arguments must be full paths and the destination folder must already exist
  • When to switch to FileSystemObject.CopyFile for wildcards and an explicit overwrite flag
  • How to copy the currently open workbook with SaveCopyAs, and how copy-then-Kill becomes a move

The mental model: three copy tools for three situations

There is no single "copy a file" command in VBA — there are three, and they are not interchangeable. The question that picks the right one is always the same: is the file open, and do you need wildcards?

  • FileCopy source, destination — the built-in statement. No references, no objects. Copies one closed file, overwrites the destination silently. This is your default for files sitting on disk.
  • FileSystemObject.CopyFile source, destination[, overwrite] — the object-model version. Same job, but it accepts wildcards (*.xlsx), takes an explicit overwrite flag, and has a CopyFolder sibling for whole trees.
  • workbook.SaveCopyAs path — the only correct way to copy a workbook that is currently open. It writes a snapshot to disk without disturbing the live file.

Everything below is a consequence of these three and the situations they belong to. Pick by asking "is it open?" first, "do I need a pattern?" second.

FileCopy overwrites silently — the opposite of Name

FileCopy never asks. If something already exists at the destination, it is replaced with no prompt and no error. This matters because the sibling statement for the disk, Name, does the exact opposite — it refuses to overwrite and raises an error. Two built-ins, two contradictory answers to "what if the destination exists?":

FileCopy "C:\Reports\March.xlsx", "C:\Backup\March.xlsx"   ' replaces Backup\March.xlsx, no warning

If a silent overwrite is what you want (refreshing a backup), that is convenient. If it is not — if that backup was yesterday's only copy — you must guard the destination yourself before you call FileCopy:

If Dir("C:\Backup\March.xlsx") = "" Then                    ' only copy if nothing is there
    FileCopy "C:\Reports\March.xlsx", "C:\Backup\March.xlsx"
End If

That one-line existence test is the subject of checking whether a file exists; here it is the difference between a safe backup and a destroyed one.

The error 70 trap: FileCopy cannot copy an open file

This is the number-one FileCopy bug. The statement asks Windows for exclusive read access to the source and exclusive write access to the destination. An open workbook is locked by Excel, so:

FileCopy ThisWorkbook.FullName, "C:\Backup\live.xlsx"   ' error 70 — "Permission denied"

fails immediately — and the file you most want to back up (the one you are working in) is exactly the one that is open. The same error 70 appears if the destination is open, or read-only, or you lack rights to the folder. There are two correct ways out:

  • If it is your workbook, use SaveCopyAs — it copies the live file without closing it (next section).
  • If it is another workbook you opened in code, Close it first, then FileCopy the file on disk.

Never "fix" error 70 with On Error Resume Next — that hides a locked file as a silent no-copy, and your backup simply never happens.

Both arguments are full paths — and the folder must exist

Two structural rules catch people repeatedly:

The destination is a full path, not a folder. FileCopy does not infer the file name from the source.

FileCopy "C:\Reports\March.xlsx", "C:\Backup\"              ' error 75 — path/file access error
FileCopy "C:\Reports\March.xlsx", "C:\Backup\March.xlsx"    ' correct — name it explicitly

The destination folder must already exist. FileCopy will not create C:\Backup\ for you. If the folder might be missing, make it first with MkDir — and remember MkDir itself errors if the folder already exists, so guard it:

If Dir("C:\Backup", vbDirectory) = "" Then MkDir "C:\Backup"
FileCopy "C:\Reports\March.xlsx", "C:\Backup\March.xlsx"

FileSystemObject.CopyFile: wildcards and an explicit overwrite flag

When you need to copy many files at once, or you want overwriting to be a decision rather than a silent default, switch to the FileSystemObject:

Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")        ' late binding — runs on any machine
fso.CopyFile "C:\Reports\*.xlsx", "C:\Backup\"              ' wildcards: every .xlsx at once
fso.CopyFile "C:\Reports\March.xlsx", "C:\Backup\March.xlsx", False   ' Overwrite:=False -> error if it exists

Three things FileCopy cannot do that CopyFile can: match a wildcard pattern, take an overwrite flag so an existing file raises error 58 instead of vanishing silently, and — with CopyFolder — copy an entire directory tree. Note the destination-folder form is allowed here (a trailing \ means "into this folder"), which is why CopyFile pairs naturally with a wildcard source. It still cannot copy an open file, though — that limitation belongs to Windows, not to the tool.

Copy the open workbook with SaveCopyAs — and copy-then-Kill is a move

For the live workbook, the answer is not a file-system copy at all — it is a workbook method:

ThisWorkbook.SaveCopyAs "C:\Backup\March-" & Format(Now, "yyyymmdd-hhnnss") & ".xlsx"

SaveCopyAs writes a copy to disk and leaves the original open and untouched — no error 70, no closing, no change to the workbook's own path. It is the correct backup call inside any long macro, and it is covered alongside Save and SaveAs in the save-workbook guide.

Finally, a useful identity: a move is a copy followed by a delete. When you cannot use Name — for instance moving a file to a different drive, which Name refuses — you fall back to copy-then-delete:

FileCopy "C:\Reports\March.xlsx", "D:\Archive\March.xlsx"   ' copy across the drive
Kill "C:\Reports\March.xlsx"                                ' then remove the original

That Kill is permanent and has no undo, so do it only after you have confirmed the copy landed.

The honest verdict: pick by "is it open?" then "do I need a pattern?"

Copying a file is trivial until the file is open or the destination already matters. Four rules keep it correct:

  • Closed file, single copyFileCopy — shortest, no setup, but it overwrites silently, so guard the destination when the existing file matters.
  • Many files or a real overwrite decisionfso.CopyFile with a wildcard and the Overwrite flag.
  • The open workbookSaveCopyAs, never FileCopy — that is the whole answer to error 70.
  • Full paths, existing folder → name the destination file explicitly and MkDir the folder first.

The instant FileCopy gives you error 70, stop reaching for On Error and ask the real question: is this file open? If it is yours, SaveCopyAs; if it is another, close it first.

How ExcelMaster helps

Choosing between FileCopy, fso.CopyFile, and SaveCopyAs — and remembering that only the last one can touch an open workbook, that the destination needs a full path, and that the folder must exist first — is a lot of ceremony for "just make a copy," and the wrong choice fails with a cryptic error 70 at run time.

ExcelMaster writes the right copy for the situation. Describe the job — "back up this workbook with a timestamp before I overwrite anything," or "copy every .xlsx in this folder into an archive" — and it produces the correct call: SaveCopyAs for the live file, fso.CopyFile with a wildcard for a batch, the MkDir guard for a missing folder, and a copy-then-Kill when you really meant a cross-drive move. You describe the outcome; it picks the tool that will not raise error 70.

Frequently asked questions

How do I copy a file in VBA?

Use the built-in FileCopy source, destination, where both arguments are full paths including the file name — for example FileCopy "C:\Reports\March.xlsx", "C:\Backup\March.xlsx". It needs no references and copies one closed file, but it overwrites the destination silently and the destination folder must already exist. To copy many files at once, use FileSystemObject.CopyFile with a wildcard source.

Why does VBA FileCopy give error 70 Permission denied?

Because the source or destination file is open or locked. FileCopy needs exclusive access, and Excel locks any open workbook — so copying the workbook you are running from always fails with error 70. To copy the currently open workbook, use ThisWorkbook.SaveCopyAs path instead; to copy another workbook you opened in code, Close it first, then FileCopy the file on disk.

How do I copy a file to another folder in VBA?

Give FileCopy a destination in that folder, as a full path with the file name: FileCopy "C:\In\a.xlsx", "C:\Out\a.xlsx". The destination folder must already exist — FileCopy will not create it, so guard with If Dir("C:\Out", vbDirectory) = "" Then MkDir "C:\Out" first. For a folder-only destination such as "C:\Out\", use fso.CopyFile rather than FileCopy.

Does VBA FileCopy overwrite an existing file?

Yes — silently, with no prompt and no error. This is the opposite of the Name statement, which refuses to overwrite. If you do not want to replace an existing file, test for it first with Dir(path) = "" or fso.FileExists(path), or use fso.CopyFile source, destination, False so an existing destination raises error 58 instead of vanishing.

How do I copy the current open workbook in VBA?

Use ThisWorkbook.SaveCopyAs "C:\Backup\copy.xlsx". SaveCopyAs writes a snapshot to disk while leaving the original open and unchanged, so it avoids the error 70 you get from FileCopy on an open file. It is the standard way to take a timestamped backup inside a long macro, and it does not alter the workbook's own saved path.

Tested in

Tested in: Excel 365 (Windows 11), VBA 7.1 — last verified 2026-08-22.

Related guides: VBA Delete File · VBA Rename File · VBA Dir · VBA FileSystemObject · VBA Save Workbook