Press F12 (or go to File → Save As → Browse), open the Save as type list, choose Excel Macro-Enabled Workbook (*.xlsm) and click Save. The file keeps its VBA code, and the macros are ready to enable the next time it opens.
Saving a workbook that contains code as a normal .xlsx removes the code. Excel warns that “the following features cannot be saved in macro-free workbooks”; clicking Yes saves the file without its macros, so click No and choose .xlsm instead.
Excel Binary Workbook (*.xlsb) also keeps macros and is usually smaller and quicker to open for large files. To save every new workbook as .xlsm, go to File → Options → Save and change Save files in this format.
From VBA, use ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "Report.xlsm", FileFormat:=xlOpenXMLWorkbookMacroEnabled. The extension and the FileFormat value must agree, or SaveAs stops with error 1004.
Macros in a file downloaded from the internet or received by email are blocked, even in .xlsm. Right-click the file, choose Properties, tick Unblock and click OK, then open it and click Enable Content.
What is a Macro-Enabled Workbook?
In Excel, when you write a macro or add VBA codes in a file, you need to save that file as a macro-enabled type in the .xlsm format. With this file type, Excel stores all the codes in the file, and you can run those codes from the file as well.

Here you have a file with the codes. Now, let’s look at how to save this file as a macro-enabled file type in Excel.
Steps to Save a Macro-Enabled Workbook
- First, go to the File tab and click on the “Save As” option, and then click Browse.
- After that, specify the location where you want to save your file.
- Next, from the “Save as type” drop-down, select “Excel Macro-Enabled Workbook”.
- In the end, click Save to save the file.
You can also press F12 to open the Save As dialog box directly. On a Mac, go to File ⇢ Save As, and from the File Format drop-down, select “Excel Macro-Enabled Workbook (.xlsm)”.

Below, you can see the file we have saved in our system with the .xlsm extension.

Points to Remember
- Once you create a macro-enabled file, you may need to enable the macros (File ⇢ Options ⇢ Trust Center ⇢ Trust Center Settings ⇢ Macro Settings) to run a code.
- You can use the Personal Macro Workbook to save all your codes in one place.
- A macro-enabled workbook from someone else (from a different system) could be a threat, so enable its macros only if you trust the source.
What Happens If You Save Macros in an .xlsx File
A normal Excel workbook (.xlsx) can’t store VBA codes. If you have codes in a file and try to save it as .xlsx, Excel shows a message that the VB project can’t be saved in a macro-free workbook.
- Click No: Excel takes you back to the Save As dialog box, where you can select “Excel Macro-Enabled Workbook”.
- Click Yes: Excel saves the file as .xlsx and removes all the codes from it.
So, always click No here if you want to keep your codes.
Other File Types That Can Store Macros
Apart from .xlsm, there are a few more file types in Excel that can store your codes:
- Excel Binary Workbook (.xlsb): Stores codes and saves the file in a binary format, which is often smaller and opens faster.
- Excel Macro-Enabled Template (.xltm): A template with codes. Each new file you create from it gets a copy of the codes.
- Excel Add-in (.xlam): Stores codes that you want to use in all your workbooks, like custom functions.
- Excel 97-2003 Workbook (.xls): The old file format, which can also store codes. Use it only if someone still works with a very old version of Excel.
Enable Macros When You Open a Macro-Enabled Workbook
With the default settings, Excel disables the macros when you open a macro-enabled workbook and shows a yellow Security Warning bar at the top. Click the Enable Content button on that bar to run the codes in the file.
If the file comes from the internet or as an email attachment, Excel on Windows blocks its macros and shows a red Security Risk bar instead, with no Enable Content button. If you trust the file, close it, right-click it in the folder, select Properties, tick Unblock on the General tab, and click OK. After that, open the file again.
For files you use every day, you can save them in a trusted location (File ⇢ Options ⇢ Trust Center ⇢ Trust Center Settings ⇢ Trusted Locations). Excel opens files from a trusted location with the macros enabled.
Make .xlsm the Default File Type
If you write codes in most of your files, you can make Excel save new files as macro-enabled by default:
- First of all, go to File ⇢ Options ⇢ Save.
- After that, in “Save files in this format”, select “Excel Macro-Enabled Workbook”.
- In the end, click OK.
Save a Workbook as Macro-Enabled with VBA
You can also save a workbook as a macro-enabled file with a code. Use the SaveAs method with the file format xlOpenXMLWorkbookMacroEnabled (its number is 52). Change the path to the folder where you want to save the file:
Sub SaveAsMacroEnabled()
ActiveWorkbook.SaveAs Filename:="C:\Reports\MyFile.xlsm", _
FileFormat:=xlOpenXMLWorkbookMacroEnabled
End Sub
The file name and the file format need to match. If you use the .xlsm extension with the .xlsx file format (or the other way around), Excel shows an error and doesn’t save the file.
Frequently Asked Questions
Can I run macros in Excel for the web?
No. You can open and edit a macro-enabled workbook in Excel for the web, but you can’t run, create or edit the VBA codes there. Open the file in the Excel desktop app to run the codes.
What is the difference between .xlsx and .xlsm?
Both use the same file format for data, formulas and formatting. The only difference is that an .xlsm file can store VBA codes, and an .xlsx file can’t.
How do I convert an .xlsm file back to .xlsx?
Go to File ⇢ Save As, select “Excel Workbook (*.xlsx)” in “Save as type” and click Save. When Excel asks about the VB project, click Yes. The new file won’t have any codes, but your original .xlsm file stays as it is.
Written by
Puneet Gogia
Microsoft MVP — Excel · Founder, Excel Champs
Twelve years of teaching Excel, and a decade before that using it as a data analyst. Every tutorial here is written from a file I actually built.