Excel VBA: How to Save a Sheet (Step-by-Step)
In this article
To save a single worksheet with VBA, copy it to a new workbook and call SaveAs on that workbook — Excel has no native "save sheet" command, so this two-step approach is the standard method. The code below copies the active sheet to a new file and saves it as an .xlsx workbook in a folder you choose. Everything runs from the Visual Basic Editor (VBE), which you open with Alt+F11 on Windows or Fn+Option+F11 on a Mac. Menu names and dialog labels can differ slightly between Excel versions, platforms and regions.
What You'll Need
- Excel for Windows or Mac (the VBA language is the same; shortcut keys differ).
- A workbook with at least one worksheet containing data or formatting you want to keep.
- A folder path where you have write permission, for example your Documents folder.
- Macro security set to allow macros: File > Options > Trust Center > Trust Center Settings > Macro Settings (Windows), or Excel > Preferences > Security on Mac.
- Optional: a macro-enabled workbook (.xlsm) if you want to keep the code with the file.
Step-by-Step
- Open the Visual Basic Editor. Press Alt+F11 (Windows) or Fn+Option+F11 (Mac). If nothing happens, use the Developer tab > Visual Basic. If the Developer tab is hidden, enable it in File > Options > Customize Ribbon.
- Insert a module. In the VBE, right-click your workbook name in the Project Explorer and choose Insert > Module. A blank code window opens.
- Paste the basic save-one-sheet macro. Use this code, replacing the path with your own folder:
Sub SaveSheet()
Dim ws As Worksheet
Set ws = ActiveSheet
ws.Copy
ActiveWorkbook.SaveAs "C:\Users\YourName\Documents\SheetCopy.xlsx", FileFormat:=xlOpenXMLWorkbook
ActiveWorkbook.Close SaveChanges:=False
End Sub - Understand what ws.Copy does. It creates a brand-new workbook containing only that sheet. The original workbook stays open and untouched. This is why the next line refers to ActiveWorkbook — the new file is now the active one.
- Run the macro. Place the cursor inside the Sub and press F5, or go back to Excel and use Developer > Macros, select SaveSheet, and click Run.
- Check the result. Open File Explorer (or Finder) and confirm SheetCopy.xlsx exists in the folder you specified. The new file should contain only the copied sheet.
- Save to a dated filename (optional). To avoid overwriting, build the name with the date:
ActiveWorkbook.SaveAs "C:\Users\YourName\Documents\Sheet_" & Format(Date, "yyyy-mm-dd") & ".xlsx", FileFormat:=xlOpenXMLWorkbook - Save as PDF instead (optional). Change the FileFormat argument to xlPDF and the extension to .pdf:
FileFormat:=xlPDF. The sheet is exported as a PDF of the printed area. - Save the workbook that holds the code. Press Ctrl+S in the VBE. If you want the macro to persist, save the host workbook as .xlsm; a plain .xlsx will strip the code.
Common Mistakes
- Using ThisWorkbook instead of ActiveWorkbook after Copy. ThisWorkbook refers to the file containing the macro, not the new copy, so the save lands on the wrong file.
- Forgetting the FileFormat argument. Without it, Excel may prompt about compatibility or save in an unexpected format.
- Backslashes in the path on Mac. Mac paths in VBA generally use colons or the standard POSIX slash form depending on version; a Windows-style path will fail.
- Saving over an open file. If SheetCopy.xlsx is already open, SaveAs raises an error. Close it first or use a unique name.
- Assuming formulas survive. Copying a sheet copies formulas, but external links may break if the referenced workbook is not available. Values-only copies need PasteSpecial.
- Leaving DisplayAlerts on. If a file with the same name exists, Excel shows an overwrite prompt. Set Application.DisplayAlerts = False around the save and restore it to True afterwards.
Tips
- Use
ThisWorkbook.Pathto save next to the source file instead of hard-coding a folder. - Wrap the save in
On Error GoTohandling so a bad path shows a clear message instead of a debug dialog. - If you only need the values, copy the sheet, then select all cells and paste values before saving.
- For a quick one-off, right-click the sheet tab > Move or Copy > Create a copy, then save the new workbook manually — no VBA required.
- Keep a backup of the original workbook before running any macro that closes workbooks.
Troubleshooting
If the macro does nothing, check that macros are enabled and that you ran the correct Sub. If you get a "Method 'SaveAs' of object '_Workbook' failed" error, the folder path is usually wrong or missing — create the folder first and verify the spelling. A "Permission denied" error means the target file is open or read-only; close it or choose another name. If the saved file is empty, confirm the sheet you copied actually had data and that you did not copy a blank sheet. On Mac, if the path fails, try building it with MacScript-free alternatives such as Environ("HOME") plus a POSIX path. If the VBE will not open, the workbook may be protected; unprotect it via Review > Unprotect Sheet. Finally, if the code disappears after saving, you saved as .xlsx — resave as .xlsm.
Frequently Asked Questions
Can VBA save just one sheet without creating a new workbook?
No. Excel saves workbooks, not individual sheets. The standard workaround is to copy the sheet to a new workbook and save that, as shown above.
Will the copied sheet keep its formulas and formatting?
Yes. ws.Copy preserves formulas, formatting, column widths and most sheet-level settings. External references may break if the linked workbook is not present.
How do I save the sheet as CSV?
Use FileFormat:=xlCSV and a .csv extension. Note that CSV saves only the active sheet's values and loses formatting and formulas.
Why does my macro save the wrong workbook?
Most often because ThisWorkbook was used after Copy. Use ActiveWorkbook immediately after ws.Copy so the save targets the new file.
Can I save to a network drive or OneDrive folder?
Yes, as long as the path is reachable and you have write permission. OneDrive paths can be slow; test with a local folder first to isolate errors.
Does this work in Excel for the web?
No. VBA macros are not supported in Excel for the web; run the code in the desktop app.