Excel VBA: Save As Non Macro-Enabled Workbook
In this article
To save a macro-enabled workbook as a standard .xlsx file with VBA, use the SaveAs method and set the FileFormat argument to xlOpenXMLWorkbook (51). For example: ActiveWorkbook.SaveAs Filename:="C:\Reports\summary.xlsx", FileFormat:=xlOpenXMLWorkbook. This strips the VBA project from the saved copy while leaving your original .xlsm file untouched. The steps below walk through doing it manually, recording the exact syntax, and handling the common warnings.
What You'll Need
- Excel on Windows or Mac with the Developer tab enabled (File > Options > Customize Ribbon > check Developer, or Excel > Preferences > Ribbon & Toolbar on Mac).
- A macro-enabled workbook (.xlsm) that already contains the macro you want to run.
- Permission to save to the destination folder, and a destination that is not the same path as the open .xlsm unless you intend to overwrite it.
- Basic familiarity with the VBA Editor (Alt+F11 on Windows, Option+F11 on Mac).
Menu labels and dialog wording can differ slightly by Excel version, platform and region, so treat the exact names below as a guide.
Step-by-Step
- Open the macro-enabled workbook. Confirm the title bar shows the .xlsm extension. If you are working in a copy, save it first so the original is safe.
- Open the VBA Editor. Press Alt+F11 (Windows) or Option+F11 (Mac). In the Project pane, find your workbook and insert a new module via Insert > Module.
- Write the SaveAs line. In the module, type a short procedure such as:
Sub SaveAsXlsx()ActiveWorkbook.SaveAs Filename:="C:\Reports\summary.xlsx", _FileFormat:=xlOpenXMLWorkbookEnd Sub
The key argument isFileFormat:=xlOpenXMLWorkbook. That constant corresponds to the standard .xlsx format. UsingxlOpenXMLWorkbookMacroEnabledwould keep macros, which is the opposite of what you want. - Point Filename at a full path. Include the folder and the .xlsx extension. If you omit the extension, Excel appends one based on the file format, but supplying it avoids surprises. Use double backslashes in VBA strings on Windows; on Mac use the POSIX-style path or
MacScript-free forward slashes as required by your version. - Decide whether to keep a copy of the original.
SaveAschanges the active workbook to the new file. If you want the original .xlsm to remain open and unchanged, either run the macro from a separate workbook that references the source, or useThisWorkbook.SaveCopyAswith an .xlsx path. Note thatSaveCopyAsdoes not change the file format of the copy in the same controlled way, so test it: in many versions it writes the copy in the current format, which would still be .xlsm. The reliable route for a true format change isSaveAsfollowed by reopening the original if needed. - Suppress the compatibility prompt if desired. When saving to .xlsx, Excel may warn that some features (macros, certain formatting) will be lost. To skip the dialog in automation, add
Application.DisplayAlerts = Falsebefore the SaveAs line and set it back toTrueimmediately after. Only do this when you are certain the loss is acceptable. - Run the macro. Place the cursor inside the procedure and press F5, or assign it to a button. Watch for a run-time error, which usually means the path is invalid, the file is open elsewhere, or the folder is read-only.
- Verify the result. Close the saved file and check its extension in File Explorer or Finder. Open it and confirm the Developer tab no longer shows your macro, and that the file opens without a security warning about macros.
- Restore your working file. If the SaveAs replaced your active workbook, reopen the original .xlsm so you keep the macro for future runs.
Common Mistakes
- Using the wrong FileFormat constant.
xlOpenXMLWorkbookMacroEnabled(52) keeps macros.xlOpenXMLWorkbook(51) is the standard .xlsx. Mixing them up is the most frequent cause of "it still has macros". - Forgetting the extension in Filename. Excel may save with the extension implied by the format, but a mismatched name such as
report.xlsmwith format 51 can confuse users and some downstream tools. - Overwriting the source file. Saving to the same path as the open .xlsm with format 51 replaces the macro-enabled file with a macro-free one, and your VBA project is gone. Always use a different filename or folder.
- Leaving DisplayAlerts off. If an error occurs before you reset it, Excel stays silent about later prompts, which can hide real problems.
- Assuming SaveCopyAs changes the format. It copies the file as-is; it is not a format converter.
- Hard-coding a user-specific path. A path like
C:\Users\YourName\Desktopfails on another machine. Build paths withEnviron("USERPROFILE")orThisWorkbook.Pathwhere appropriate.
Tips
- Store the destination in a variable so you can change it in one place:
Dim outPath As String. - Use
ThisWorkbookinstead ofActiveWorkbookwhen the macro should always act on the file that contains it, regardless of which window is focused. - Add a timestamp to the filename (for example with
Format(Now, "yyyymmdd_hhmm")) to avoid overwriting previous exports. - If the goal is to distribute a report, consider saving to .xlsx and then zipping or emailing it; recipients avoid the macro security bar entirely.
- Keep a version of the .xlsm under source control or a backup folder, since the export process never needs to touch it.
Troubleshooting
Run-time error 1004. This usually means the path does not exist, the filename contains invalid characters, or the destination file is open in another Excel window. Close the other file, create the folder, and retry.
The saved file still prompts about macros. Check the FileFormat value. If it is 52, change it to 51. Also confirm you are not saving over the original .xlsm.
Formatting or features disappear. That is expected when moving from .xlsm to .xlsx: macros, some ActiveX controls and certain custom XML parts are not carried over. Save a copy of the original before exporting if you need to preserve them.
Permission denied. The folder may be read-only or synced by a service that locks files. Choose a local folder such as Documents, or run Excel with sufficient rights.
Mac path issues. On macOS, VBA paths use colons in some contexts and slashes in others depending on version. Test with a simple path first and adjust. If the macro was written on Windows, expect to edit the path separators.
Nothing happens when you run it. Confirm macros are enabled for the file, that the procedure is in a standard module (not a sheet module), and that no On Error Resume Next is hiding the failure.
Frequently Asked Questions
Does SaveAs with xlOpenXMLWorkbook delete my macros permanently?
It removes the VBA project from the newly saved .xlsx file. Your original .xlsm is unaffected unless you saved over it. Reopen the original to keep working with macros.
Can I save as .xlsx without changing the active workbook?
Not directly with SaveAs, which switches the active file. Workarounds include running the export from a separate controller workbook that opens the source, saves a copy as .xlsx, then closes it without saving.
What is the difference between xlOpenXMLWorkbook and xlOpenXMLWorkbookMacroEnabled?
The first is the standard .xlsx format with no macros. The second is .xlsm and retains VBA. Use the first for a macro-free export.
Will formulas and charts survive the conversion?
Standard formulas, values and most charts do. Macros, some ActiveX controls and certain advanced features do not. Review the exported file before distributing it.
Can I do this on Excel for Mac?
Yes. The VBA SaveAs method and the FileFormat constants work on Mac, but path syntax differs. Test the path and adjust separators as needed.
How do I stop the compatibility warning dialog?
Set Application.DisplayAlerts = False before SaveAs and reset it to True after. Understand that this suppresses all alerts during that window, including ones you might want to see.