logo
search
VBA & Macro Problems

How to Remove VBA from an Excel Workbook Before Save As

Maira MehtabMaira Mehtab Sep 22, 2026 869 views

Question details

The user wants to save an XLSM report template containing VBA macros under a new filename, ensuring the newly saved file is completely free of any VBA code.

Product
Excel
Device & OS
not provided
Scenario
Generating reports from a macro-enabled (XLSM) template and saving the formatted output as a new workbook without retaining the original VBA scripts.
Observed behavior
The user needs a programmatic method within their existing VBA script to save the completed workbook as a new file type that strips out all macros.
Before you start

Ensure you have saved a backup copy of your original XLSM template before testing your save automation to prevent accidental overwriting.

Solution 1Recommended

Use VBA to Save the Workbook as a Macro-Free XLSX File

The most efficient way to strip VBA code automatically is to use VBA itself to save the workbook as a standard XLSX file, suppressing the compatibility warning during the process.

Since the XLSX file format natively prohibits the inclusion of VBA code, forcing an XLSM file to save as an XLSX file will automatically strip out all modules, forms, and macro code. To do this seamlessly via VBA without prompting the user with warning dialogs, you must temporarily disable Excel's application alerts.

1
Disable application alerts

In your existing VBA script, right before the save command, insert `Application.DisplayAlerts = False`. This stops Excel from showing the warning message that saving as XLSX will cause macro loss.

2
Execute the SaveAs method

Add the command to save the workbook as an XLSX format: `ActiveWorkbook.SaveAs Filename:="C:\Path\To\Your\NewFile.xlsx", FileFormat:=xlOpenXMLWorkbook`. Ensure you replace the path with your desired destination.

3
Re-enable application alerts

Immediately after the save command, restore the default warning prompts by adding `Application.DisplayAlerts = True` to ensure subsequent operations alert the user normally.

Format confirmation: Setting FileFormat to xlOpenXMLWorkbook is the critical parameter that ensures the VBA project is dropped when saving the new file.
Advanced VBA support in WPS Spreadsheet

Use WPS Spreadsheet to Manage Macros and Save Macro-Free Files

WPS Office Spreadsheet offers excellent support for VBA macros. You can seamlessly run your reporting scripts and save the final results as standard, macro-free XLSX files without any compatibility issues.

  1. 1. Open your macro-enabled file: Launch WPS Spreadsheet and open your XLSM template file.
  2. 2. Run your data macros: Navigate to the Developer tab, click 'Macros', select your formatting script, and click 'Run'.
  3. 3. Save as a macro-free format: Click 'Menu' in the top-left corner, select 'Save As', and choose 'Microsoft Excel Workbook (*.xlsx)'. WPS Spreadsheet will save the file without the VBA code.
Fully compatible with Microsoft Excel's VBA and macro scriptsSave seamlessly to macro-free .xlsx formats as well as .xls and .csvLightweight application that runs macro templates efficientlyFree and highly compatible alternative to Microsoft Office
microsoft office alternative - wps office

Frequently Asked Questions

Why do I get a warning when manually saving an XLSM file as an XLSX?

Excel warns you because the XLSX file format cannot store VBA projects. If you proceed with the save, all macros, modules, and userforms will be permanently removed from the newly saved copy.

Does saving as an XLSX file affect my original XLSM template?

No. When you use the 'Save As' function (either manually or via VBA), Excel creates a new file. Your original XLSM template remains unchanged on your hard drive and retains all of its VBA code.

How do I manually remove VBA code without changing the file format?

If you need to keep the file as an XLSM but remove the code, press Alt + F11 to open the VBA Editor. In the Project Explorer pane on the left, right-click each module, class, or userform, select 'Remove', choose 'No' when asked to export, and then save the workbook.