Excel VBA Workbook Save As: Step-by-Step Guide
In this article
To save an Excel workbook under a new name or format with VBA, use the SaveAs method of the Workbook object. The shortest working version is ActiveWorkbook.SaveAs "C:\Folder\NewName.xlsx" — but you need to add the file format argument if you are changing the extension, and you need to decide whether to keep or replace the original. This guide walks through the exact syntax, the common pitfalls, and how to handle prompts and overwrites.
What You'll Need
- Excel with the Developer tab enabled (File > Options > Customize Ribbon > check Developer).
- A workbook you are allowed to modify — test on a copy first.
- Basic familiarity with the VBA editor (Alt+F11).
Step-by-Step
- Open the VBA editor. Press Alt+F11 (Windows) or Option+F11 (Mac). In the Project Explorer, right-click your workbook and choose Insert > Module.
- Write the basic SaveAs statement. In the module, type a Sub procedure. For example:
This saves the active workbook to the specified path with the default format. If the file already exists, Excel will prompt to overwrite (unless you disable alerts).Sub SaveAsNewName() ActiveWorkbook.SaveAs "C:\Reports\Budget_2025.xlsx" End Sub - Specify the file format when changing the extension. If you save as .xlsm, .xlsb, .csv, or .pdf, you must set the FileFormat parameter. For example, to save as macro-enabled:
Common constants: xlOpenXMLWorkbook (xlsx), xlOpenXMLWorkbookMacroEnabled (xlsm), xlCSV (csv), xlExcel8 (xls 97-2003). Omitting the format when the extension implies a different type can cause Excel to save in the wrong format or show a warning.ActiveWorkbook.SaveAs "C:\Reports\Budget_2025.xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled - Decide whether to keep the original open. SaveAs changes the active workbook's path and name to the new file. If you want to keep the original open and save a copy, use
SaveCopyAsinstead:
SaveCopyAs does not change the active workbook's name and does not prompt to overwrite.ActiveWorkbook.SaveCopyAs "C:\Reports\Budget_2025_Backup.xlsx" - Suppress overwrite and format prompts (optional). If you want to overwrite without a dialog, set
Application.DisplayAlerts = Falsebefore SaveAs and restore it to True afterward. Always restore it, even if an error occurs — use an error handler if needed. Example:Application.DisplayAlerts = False ActiveWorkbook.SaveAs "C:\Reports\Budget_2025.xlsx" Application.DisplayAlerts = True - Handle the read-only case. If the target file is open or marked read-only, SaveAs will fail. Check
ActiveWorkbook.ReadOnlyor useDirto test if the file exists, and choose a different name or close the other instance first. - Run the macro. Press F5 while the cursor is inside the Sub, or assign the macro to a button. Verify the file appears in the target folder and that the workbook's title bar shows the new name.
Common Mistakes
- Forgetting the FileFormat argument. Saving a .xlsm as .xlsx without setting the format will strip macros or trigger a warning. Always match the constant to the extension.
- Using a path that does not exist. SaveAs does not create folders. Use
MkDiror ensure the folder exists beforehand. - Leaving DisplayAlerts off. If your macro errors before resetting it, Excel will stop showing alerts for the rest of the session. Wrap it in error handling.
- Assuming SaveAs keeps the original open. It does not — the active workbook becomes the new file. Use SaveCopyAs if you need both.
- Hard-coding a user-specific path. Paths like C:\Users\YourName\... will fail on other machines. Use
Environ("USERPROFILE")orThisWorkbook.Pathto build portable paths.
Tips
- Use
ThisWorkbookinstead ofActiveWorkbookwhen the macro should always act on the workbook containing the code, regardless of which workbook is active. - Build the filename with a date stamp to avoid overwrites:
Format(Date, "yyyy-mm-dd"). - Test on a copy first — SaveAs changes the live file's identity, and undoing is not possible.
- If you need to save as PDF, use
ExportAsFixedFormatrather than SaveAs with xlPDF, which is not a valid FileFormat constant for SaveAs in all versions.
Troubleshooting
If the macro errors with "Method 'SaveAs' of object '_Workbook' failed," check these in order: (1) the folder path exists and you have write permission; (2) the file is not open in another Excel instance; (3) the filename does not contain invalid characters (\ / : * ? " < > |); (4) the FileFormat constant matches the extension. If you get a "SaveAs method cannot be used" error, the workbook may be protected or the path may be a network location that is temporarily unavailable. Try saving to a local folder to isolate the cause. If the file saves but macros disappear, you likely used xlOpenXMLWorkbook instead of xlOpenXMLWorkbookMacroEnabled. If the overwrite prompt keeps appearing despite DisplayAlerts = False, confirm you set it on the Application object, not the Workbook. On Mac, path separators are colons in some VBA contexts — use Application.PathSeparator or the MacScript approach if you need cross-platform code.
Frequently Asked Questions
Can I save as a new file without changing the active workbook?
Yes — use SaveCopyAs. It writes a copy to disk and leaves the open workbook unchanged.
How do I save as .xlsm from VBA?
Use ActiveWorkbook.SaveAs "path\name.xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled.
Why does my macro save the file with the wrong extension?
Because the FileFormat argument was omitted or set to a constant that does not match the extension you provided. Excel uses the FileFormat to decide the actual type, not the text in the filename.
Can I overwrite an existing file without a prompt?
Set Application.DisplayAlerts = False before SaveAs and restore it to True immediately after. Always restore it in an error handler too.
Does SaveAs work with OneDrive or SharePoint paths?
Yes, if the path is a valid local sync folder or a mapped URL that Excel can resolve. Use the full path as shown in File Explorer; if it fails, save locally first and then upload.
What happens to the original file after SaveAs?
It remains on disk unchanged. The open workbook now points to the new file, so subsequent saves go to the new location.