TL;DR —
Name oldPath As newPathrenames a file — but ifnewPathpoints to a different folder, VBA moves the file there. One statement does both jobs. And unlikeFileCopy,Namerefuses to overwrite: if the target already exists it raiseserror 58instead of replacing it.
Sub RenameAndMove()
Name "C:\Reports\draft.xlsx" As "C:\Reports\final.xlsx" ' same folder -> a rename
Name "C:\Reports\final.xlsx" As "C:\Archive\final.xlsx" ' different folder -> a MOVE
End Sub
Renaming and moving feel like two different operations, so most people go looking for two different
commands. VBA folds them into one statement — Name — and the surprise is not that it renames, but that the
same statement quietly moves the file the moment the destination folder differs. Add its stubborn refusal
to overwrite, and Name behaves unlike any other disk tool in VBA. Learn those two traits and it becomes
predictable.
What you'll learn
- The mental model —
Nameis rename and move in one statement - Why
Namerefuses to overwrite witherror 58— the opposite ofFileCopy - Why
Namecannot cross drives, and howFileCopy+KillorMoveFiledoes that job - The other errors — missing source (
53), open file (70) — and how to guard them - The
Name old As newsyntax trap, and why it reads oddly next to the.Nameproperty - When to prefer
FileSystemObject.MoveFile, and the safe rename pattern for unattended macros
The mental model: rename and move are the same statement
The key insight is that Name does not care about the concept of renaming versus moving — it cares only
about the old path and the new path. It removes the directory entry at the old path and creates one
at the new path. If the folder part is the same, that reads to you as a rename. If the folder part differs,
the file ends up somewhere else — a move:
Name "C:\In\a.xlsx" As "C:\In\b.xlsx"— same folder, new name → renameName "C:\In\a.xlsx" As "C:\Out\a.xlsx"— new folder, same name → moveName "C:\In\a.xlsx" As "C:\Out\b.xlsx"— new folder and new name → move and rename at once
There is no separate "move" statement in built-in VBA — Name is the move. Once you see it as "change the
path," every behaviour below follows.
Name refuses to overwrite — the opposite of FileCopy
Here is where Name breaks from the rest of the disk toolkit. If a file already exists at the new path,
Name will not replace it — it stops with an error:
Name "C:\Reports\draft.xlsx" As "C:\Reports\final.xlsx" ' error 58 — "File already exists"
Compare the three built-ins and their contradictory answers to "what if the destination exists?":
Kill— deletes with no prompt (destination is the point).FileCopy— overwrites the destination silently.Name— refuses and raiseserror 58.
This is a safety feature: Name will never clobber an existing file by accident. But it also means an
unattended macro halts the instant the target name is already taken. If you intend to replace the target,
delete it first — and guard that with an existence check:
If Dir("C:\Reports\final.xlsx") <> "" Then Kill "C:\Reports\final.xlsx" ' clear the target
Name "C:\Reports\draft.xlsx" As "C:\Reports\final.xlsx" ' now it succeeds
That existence test is the check-if-file-exists one-liner again; here it is
what keeps a scheduled rename from stopping on error 58.
Name cannot cross drives — use FileCopy + Kill or MoveFile
Name moves files within a drive by rewriting a directory entry, which is fast and cheap. It cannot move
a file to a different drive, because that requires physically copying the bytes:
Name "C:\Reports\March.xlsx" As "D:\Archive\March.xlsx" ' error 74 — "Can't rename with different drive"
A cross-drive move is a copy plus a delete — exactly the identity from the copy-file guide:
FileCopy "C:\Reports\March.xlsx", "D:\Archive\March.xlsx" ' copy the bytes to the other drive
Kill "C:\Reports\March.xlsx" ' then remove the original
Do the Kill only after confirming the copy landed — that delete is permanent.
Or let the FileSystemObject do both in one call with MoveFile, which
handles cross-drive moves internally (covered below).
The other errors: missing source and open files
Two more run-time errors round out Name, and both have the same fixes as the rest of the file statements:
Name "C:\Reports\missing.xlsx" As "C:\Reports\x.xlsx" ' error 53 — source not found
Name "C:\Reports\open.xlsx" As "C:\Reports\x.xlsx" ' error 70 — file is open/locked
error 53— the source does not exist. Guard withIf Dir(oldPath) <> "" Thenbefore renaming.error 70— the file (or its target) is open. You cannot rename a workbook that is open in Excel;Closeit first, then rename the file on disk.
So a robust rename guards three things: source exists, target does not exist (or was just deleted), and the file is not open. That is more care than a rename seems to need, but it is exactly what keeps an unattended macro from stalling on a dialog-free run-time error.
The syntax trap: Name old As new, not Name(old, new)
Name is a statement, not a function, and its syntax is unusual — the two paths are joined by the
keyword As, with no parentheses and no comma:
Name oldPath As newPath ' correct — statement form with the As keyword
Name(oldPath, newPath) ' wrong — this is not how Name works; compile/parse error
It also reads confusingly because VBA already uses .Name as a property all over the object model
(ws.Name, wb.Name). The file-renaming Name is a top-level statement, unrelated to those properties;
seeing Name x As y on its own line is the tell that it is the file operation, not a property read.
FileSystemObject.MoveFile and the safe rename pattern
The object-model alternative is MoveFile, and it is often the nicer choice for moves:
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject") ' late binding — runs on any machine
fso.MoveFile "C:\Reports\March.xlsx", "D:\Archive\" ' handles cross-drive; trailing \ = into folder
MoveFile moves across drives without a manual copy-then-delete, accepts wildcards, and takes a
folder-style destination (trailing \). Like Name, it refuses to overwrite — so the destination must
be clear first. For a pure in-place rename, there is no dedicated FSO method; Name is still the
shortest tool, or MoveFile with a full new path in the same folder.
Putting it together, the safe rename that will not stall an unattended macro:
Dim src As String, dst As String
src = "C:\Reports\draft.xlsx": dst = "C:\Reports\final.xlsx"
If Dir(src) = "" Then Exit Sub ' nothing to rename
If Dir(dst) <> "" Then Kill dst ' clear the target so Name won't hit error 58
Name src As dst ' same-drive rename or move
The honest verdict: Name for same-drive, copy-plus-delete for cross-drive
Name is the one-line answer for renaming and for moving within a drive — provided you respect its two
defining traits. Four rules:
- Rename or same-drive move →
Name old As new— the whole job in one statement. - It refuses to overwrite → clear the target first (
Killafter an existence check), or it stops onerror 58. - Cross-drive move →
Namecan't; useFileCopy+Kill, orfso.MoveFile. - Guard source, target, and open state → so a scheduled rename never stalls on
error 53,58,70, or74.
The moment you see error 74, stop trying to make Name cross the drive — that is Windows telling you a
move across volumes is a copy, and the tool changes accordingly.
How ExcelMaster helps
Renaming a file safely means remembering that Name also moves, that it refuses to overwrite, that
it cannot cross drives, and that it stalls on a missing source or an open file — four separate traps
around a statement that looks like it should just rename.
ExcelMaster writes the rename that will
not stall. Describe the job — "rename each export with today's date," or "move finished files to the archive
drive" — and it produces the correct statement: Name for a same-drive rename or move with the target-clear
guard, a FileCopy-plus-Kill or fso.MoveFile when the
destination is on another drive, and existence checks so error 58 or 74 never halts an unattended run.
You describe the outcome; it picks between rename, move, and copy-plus-delete for you.
Frequently asked questions
How do I rename a file in VBA?
Use the Name statement with the As keyword: Name "C:\In\old.xlsx" As "C:\In\new.xlsx". It renames the
file in place when both paths are in the same folder. Guard it first — Name raises error 53 if the
source is missing and error 58 if a file with the new name already exists, so check the source exists and
clear the target (with Kill after an existence test) before renaming.
Does the VBA Name statement move files too?
Yes. Name changes the file's path, so if the new path is in a different folder, VBA moves the file
there — Name "C:\In\a.xlsx" As "C:\Out\a.xlsx" moves a.xlsx from In to Out. There is no separate
move statement in built-in VBA; Name is the move, as long as both folders are on the same drive. For a
cross-drive move, use FileCopy plus Kill, or fso.MoveFile.
Why does VBA Name give error 58 File already exists?
Because a file with the new name already exists, and Name refuses to overwrite — the opposite of
FileCopy, which overwrites silently. This is a safety feature, but it halts an unattended macro. To
replace the target, delete it first: If Dir(newPath) <> "" Then Kill newPath, then Name oldPath As newPath. Always confirm you actually intend to discard the existing file before Killing it.
How do I move a file to another drive in VBA?
Name cannot cross drives — Name "C:\a.xlsx" As "D:\a.xlsx" raises error 74, "Can't rename with
different drive." A cross-drive move is a copy plus a delete: FileCopy "C:\a.xlsx", "D:\a.xlsx" then Kill "C:\a.xlsx" (only after confirming the copy succeeded). Alternatively, fso.MoveFile from the
FileSystemObject performs a cross-drive move in a single call.
What is the difference between the Name statement and the Name property?
They are unrelated. The Name statement renames or moves a file on disk — Name oldPath As newPath, a
top-level statement using the As keyword. The .Name property reads or sets an object's name in the
Excel model, such as ws.Name for a worksheet or wb.Name for a workbook. Seeing Name x As y on its own
line is the file operation; something.Name is the property.
Tested in
Tested in: Excel 365 (Windows 11), VBA 7.1 — last verified 2026-08-22.
Related guides: VBA Copy File · VBA Delete File · VBA Check If File Exists · VBA Dir · VBA FileSystemObject
