Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel VBA: Save a Copy of a Workbook (Step-by-Step)

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To save a copy of a workbook with VBA, use the SaveCopyAs method: ThisWorkbook.SaveCopyAs "C:\Backups\MyFile_copy.xlsx". This writes a duplicate file to the path you specify while leaving the open workbook untouched — no changes to its name, its location, or its saved state. If you need the copy to become the active file instead, use SaveAs or SaveAs2. The steps below cover both, plus the filename handling that trips most people up.

What You'll Need

  • Excel on Windows or Mac with the Developer tab enabled (File > Options > Customize Ribbon > check Developer; on Mac, Excel > Preferences > Ribbon & Toolbar).
  • A workbook you can save, and a folder path you have write permission to. Network paths and OneDrive-synced folders work but can be slower.
  • Basic familiarity with the VBA editor (Alt+F11 on Windows, Option+F11 on Mac).
  • Macro-enabled file format (.xlsm) if you want the macro to live in the workbook itself.

Step-by-Step

  1. Open the VBA editor. Press Alt+F11 (Windows) or Option+F11 (Mac). In the Project pane, find your workbook and right-click it to insert a new module (Insert > Module). Menu labels can differ slightly by Excel version and platform.
  2. Write the basic SaveCopyAs procedure. In the module, paste:
    Sub SaveCopy()
      ThisWorkbook.SaveCopyAs "C:\Backups\Book1_copy.xlsx"
    End Sub
    This creates the file at that exact path. The open workbook keeps its current name and is not marked as saved or modified.
  3. Build the path from the workbook's own location. Hard-coded paths break when the file moves. Use:
    Dim p As String
    p = ThisWorkbook.Path & "\" & ThisWorkbook.Name
    Then append a suffix before the extension. Splitting the extension is the reliable way: use InStrRev to find the last dot, or simply build the name yourself if you control it.
  4. Add a timestamp so copies do not overwrite each other. Format(Now, "yyyy-mm-dd_hh-nn") produces a sortable, filesystem-safe string. Combine it with the base name, for example "Book1_" & Format(Now, "yyyy-mm-dd_hh-nn") & ".xlsx". Avoid colons, slashes and question marks in filenames — Windows rejects them.
  5. Check the folder exists before saving. SaveCopyAs does not create folders. Use Dir(path, vbDirectory) to test, and MkDir to create a single-level folder if missing. For nested folders, create each level in turn.
  6. Choose SaveCopyAs vs SaveAs. Use SaveCopyAs when you want a snapshot and want to keep working in the original. Use ThisWorkbook.SaveAs Filename:=p, FileFormat:=xlOpenXMLWorkbook when the copy should become the active document — note this changes the workbook's name and path, so subsequent saves go to the new file.
  7. Handle the file format correctly. If the workbook contains macros, saving as .xlsx via SaveAs strips the VBA project. Use xlOpenXMLWorkbookMacroEnabled (.xlsm) to keep macros. SaveCopyAs preserves whatever the current file is, so a .xlsm stays a .xlsm.
  8. Suppress prompts and alerts. Wrap the save in Application.DisplayAlerts = False … Application.DisplayAlerts = True so overwrite and compatibility prompts do not block an automated run. Always restore the setting, even if an error occurs — use an error handler or a cleanup line.
  9. Test with a throwaway file. Run the macro on a scratch workbook first and confirm the copy appears in the target folder, opens correctly, and contains the expected data. Check the original is unchanged.

Common Mistakes

The most frequent error is passing a folder path instead of a full file path to SaveCopyAs. It needs the filename and extension, not just the directory. Second is assuming the folder exists — it must already be there. Third is using SaveAs when a copy was intended; that renames the live workbook and can break links and references. Fourth is forgetting that .xlsx cannot hold macros, so a SaveAs to .xlsx silently drops your code. Fifth is leaving DisplayAlerts off after an error, which hides prompts for the rest of the session. Finally, paths with spaces are fine, but paths with unescaped quotes or trailing backslashes are not — build them carefully.

Tips

Store the backup folder in a named range or a cell on a settings sheet rather than in code, so non-technical users can change it. Use Environ("USERPROFILE") to build a per-user path that works across machines. If you are backing up on a schedule, tie the macro to Workbook_BeforeSave or a timer, but keep the copy step fast and non-blocking. Log each save to a text file or a sheet so you can see what ran and when. Test on a copy of the real workbook, not the original, until you are confident. Keep filenames under about 200 characters total including the path; Windows has a limit and long OneDrive paths hit it sooner. If the workbook is on OneDrive or SharePoint, expect occasional lock errors when the sync client is busy — retry after a short pause.

Troubleshooting

If you get "Path not found" (error 76), the folder does not exist or the drive is not mapped — create it or fix the path. "Permission denied" (error 70) usually means the file is open elsewhere, read-only, or the folder is protected; close the other copy or choose a different folder. "Bad file name or number" (error 52) points to invalid characters or a missing extension. If the macro runs but no file appears, check you are looking in the right folder and that the path is absolute, not relative. If Excel hangs, a dialog may be waiting behind the window — turn off alerts temporarily and rerun. On Mac, path separators are colons in some contexts but VBA generally accepts forward slashes; use Application.PathSeparator to be safe. If the saved copy is corrupt, confirm the source workbook opens cleanly and that you are not saving mid-calculation.

Frequently Asked Questions

Does SaveCopyAs change the open workbook?

No. It writes a duplicate file and leaves the original's name, path and saved state unchanged.

Can I save a copy to a folder that does not exist?

No. Create the folder first with MkDir or by hand; SaveCopyAs will not create it.

Will SaveCopyAs keep my macros?

Yes, because it copies the file as-is. SaveAs to .xlsx will strip macros; use .xlsm to keep them.

How do I add a date to the filename?

Use Format(Now, "yyyy-mm-dd") in the string. Avoid colons and slashes, which are invalid in filenames.

Why does it fail on OneDrive or a network drive?

Usually a lock or sync conflict. Wait a moment, close other copies, and retry; check you have write permission.

What is the difference between SaveCopyAs and SaveAs?

SaveCopyAs writes a separate file and keeps you in the original. SaveAs makes the new file the active workbook.