An Excel macro file is a workbook that can store VBA code to automate tasks; the usual format is an Excel Macro-Enabled Workbook with the .xlsm extension. To keep macros when saving, choose Excel Macro-Enabled Workbook (*.xlsm) as the file type—an ordinary .xlsx file cannot store VBA macros.
What an Excel macro file contains
A macro is a set of instructions that Excel can run to perform actions such as formatting a report, cleaning data, creating worksheets, or preparing a print-ready layout. Many Excel macros are written in Visual Basic for Applications, usually shortened to VBA. A macro-enabled workbook can contain VBA modules, forms, and other project components alongside ordinary spreadsheet content such as worksheets, formulas, tables, and charts.
The file extension helps distinguish formats, but it does not tell you whether every macro in a workbook is safe or useful. A workbook saved as .xlsm can contain no macros at all, while a macro-enabled file may contain code that runs only when someone deliberately starts it or code linked to a workbook event. Treat a macro file as both a spreadsheet and a small program.
- .xlsm: Macro-enabled Excel workbook; the standard choice for a workbook that needs to retain VBA.
- .xlsx: Standard Excel workbook; it does not retain VBA macro code.
- .xltm: Macro-enabled Excel template, used as a starting point for new workbooks.
- .xlsb: Excel binary workbook format, which can also contain VBA macros.
- .xls: Older Excel 97–2003 workbook format, which can contain macros but has legacy limitations.
Why the file extension matters
When you save a workbook containing VBA as .xlsx, Excel warns that the format does not support macros. If you proceed with a macro-free format, the VBA project is removed from the saved copy. The worksheet data and many ordinary workbook features can remain, but the automation code will not. If you want both the spreadsheet and its VBA project, save as .xlsm or another compatible macro-capable format.
Changing the extension by renaming a file in File Explorer or Finder is not the same as converting it. Use Excel’s Save As command so the application writes the content in the selected format. Also remember that VBA might be stored somewhere other than the workbook you are looking at: for example, a user’s Personal Macro Workbook or an Excel add-in can supply macros that are available in other files. A workbook without embedded VBA may therefore still be used alongside macros on a particular computer.
How to save a workbook as XLSM
In Excel for Microsoft 365 on Windows, use these steps:
- Open the workbook and, if it contains important data, first make a separate backup copy.
- Select File > Save As > Browse.
- Choose a folder and enter a file name.
- Open Save as type and select Excel Macro-Enabled Workbook (*.xlsm).
- Select Save. If Excel displays a format warning, confirm that you want to keep the workbook in the macro-enabled format.
On a Mac, use File > Save As, then choose the Excel Macro-Enabled Workbook format in the format list. The wording and dialog layout can vary slightly by Excel release. If you are starting a new macro project, save as .xlsm before distributing it. Saving early makes it less likely that you will accidentally keep working in an .xlsx copy and lose new code when you save.
Creating and storing a VBA macro
To show the Developer tab in Excel for Microsoft 365 on Windows, go to File > Options > Customize Ribbon, select the Developer checkbox under Main Tabs, and select OK. Then select Developer > Visual Basic to open the VBA editor. In the editor, choose Insert > Module and place a procedure in the module. Save the workbook as .xlsm so the code is kept with it.
On a Mac, enable the tab through Excel > Settings > Ribbon & Toolbar and select Developer under Main Tabs. You can then use Developer > Visual Basic. Some VBA features and connections to other applications differ between Windows and Mac, so code that works on one operating system may need changes on the other.
This example bolds the font in the currently active cell and adds a light fill. It is intentionally small; it demonstrates a macro stored in a workbook, not a full reporting workflow. Before running code that changes data or formatting, save a copy of the workbook. Macros cannot be undone with Ctrl+Z, and the example’s formatting change is no exception.
Sub FormatActiveCell()
' Format the currently active cell.
Dim target As Range
Set target = ActiveCell
target.Font.Bold = True
target.Interior.Color = RGB(221, 235, 247)
End Sub
How to open and run a macro
Opening an .xlsm file does not always mean its macros are enabled. Excel may show a security notice or block code, depending on where the file came from and the computer’s security policy. Read the notice and establish that you trust the workbook and its source before allowing its code to run.
To run a macro you have chosen to trust, select Developer > Macros, select the macro name, and choose Run. On Windows, Alt+F8 opens the Macro dialog. On a Mac, Option+F8 commonly opens the corresponding dialog; a keyboard’s Fn setting may affect function-key shortcuts. The VBA editor shortcut is Alt+F11 on Windows and commonly Option+F11 on Mac, sometimes with Fn. You can also assign a shortcut or add a macro button, but do this only after confirming what the code does.
Excel for the web can open and edit many workbook contents, but it cannot create, run, or edit VBA macros. To use VBA, open the workbook in the desktop Excel application. A macro button or control in a workbook may be visible in the browser without being able to execute its VBA action there.
Macro security and safe handling
VBA can change cells, delete sheets, access files, or interact with other applications. That flexibility is why Excel applies security controls. On Windows, macro settings are available at File > Options > Trust Center > Trust Center Settings > Macro Settings. The available controls can be managed by an organization, and a workplace policy may prevent you from changing them. Avoid turning on all macros globally just to open one file; a safer approach is to verify the source and follow your organization’s approved process.
Use a few checks before enabling macros:
- Confirm who sent the file and whether you expected a macro-enabled workbook.
- Ask what the macro is supposed to do, especially if it requests permission or produces an unexpected security prompt.
- For business-critical code, have an appropriate IT or security contact review it. A digital signature can help identify a publisher, but it is not a guarantee that code is harmless.
- Keep an untouched copy before running a macro that changes workbook content.
- Do not add an unfamiliar folder to Trusted Locations merely to bypass a warning. Files placed there may receive fewer security checks.
Files obtained from the internet can receive additional protections, and newer Office security behavior may block macros from files marked as coming from an untrusted source. Do not try to bypass that block just because the workbook is inconvenient to open. Verify the file and ask the sender or your administrator for the approved way to handle it. The exact prompt and available options can depend on the Excel version, Windows settings, and organizational policy.
Sharing and compatibility
When sharing an .xlsm file, tell recipients that it contains macros and explain what those macros do. Send it through an approved channel, and do not assume that every recipient can run it: their Excel settings may block macros, they may use Excel for the web, or their organization may prohibit VBA. A macro can also rely on a particular folder path, printer, add-in, or Windows-only component, so test the intended workflow in the recipient’s environment where practical.
Excel for Windows and Excel for Mac both support many VBA tasks, but they are not identical platforms. Code that calls Windows-specific system features, uses certain external libraries, or assumes a Windows file path may not work on a Mac. In addition, a workbook’s VBA will not run in spreadsheet programs that do not support Excel VBA. If recipients only need the final results, consider sending a separate macro-free copy as .xlsx, after confirming that they do not need the automation or embedded code.
Co-authoring and cloud storage do not make VBA run in a browser. A workbook can be stored in a cloud location and opened in desktop Excel, but the macro execution still depends on the desktop app and its security rules. Keep the macro-enabled original clearly identified so users do not confuse it with a macro-free export.
Common problems and what to check
- The macro disappeared after saving: Check whether the file was saved as
.xlsx. Return to the original macro-enabled copy if possible, then save it as.xlsm; changing an extension later will not restore removed code. - The Macros list is empty: Confirm that the code is stored in this workbook, that it is a runnable procedure in a standard module, and that the file is not being opened in Excel for the web.
- The macro is disabled: Review Excel’s security notice and the file’s source. If a work policy blocks it, contact the administrator rather than changing protected settings.
- A macro works on one computer but not another: Check for hard-coded file paths, missing add-ins, different permissions, operating-system-specific code, and different Excel security settings.
- The workbook opens in Protected View or read-only mode: The file’s source or permissions may restrict editing. Verify it is safe and use the approved method to enable editing; do not treat a warning as a routine obstacle.
When a macro file is the right choice
Use an .xlsm file when the workbook needs VBA automation and the people who use it have desktop Excel with permission to run that code. A recurring task such as applying a standard report layout to a selected sheet may be a reasonable macro use, particularly when the workflow is clearly documented and the workbook is maintained.
A macro is not automatically the best solution for every repeated task. Excel features such as tables, formulas, filters, and built-in data tools may handle a job with less code and fewer security concerns. For repeatable data preparation, Power Query may be an option; for a workflow that must run in a browser or across different spreadsheet products, consider a tool designed for that environment. Choose based on the task, user access, maintenance needs, and security requirements—not simply because a macro can automate it.
Frequently Asked Questions
Is an Excel macro file the same as an XLSM file?
An .xlsm file is the most common Excel macro-enabled workbook format, but it is not the only format that can store VBA. Excel binary workbooks (.xlsb), macro-enabled templates (.xltm), and some older .xls files can also contain macros.
Can I save a macro file as XLSX?
You can save a copy as .xlsx, but that format cannot keep VBA. Excel warns that the macros will be removed from that saved copy. Keep an .xlsm original if you need to retain the code.
Can I run an Excel macro without enabling all macros?
Excel’s security controls and organizational policies determine what can run. Do not enable all macros to get past a warning. Verify the workbook and follow the approved security process for that specific file.
Can Excel for the web run an XLSM macro?
No. Excel for the web can work with many workbook contents, but VBA macros must be run or edited in desktop Excel that supports them.
Why does Excel block macros in a downloaded file?
Office may treat internet-sourced files as untrusted and block their macros to reduce the risk of harmful code. Confirm the sender and file, then follow your organization’s guidance rather than trying to disable the protection indiscriminately.
Related
- Excel Data Validation Date Picker: Setup and Options
- Excel Data Validation for Dates: Rules and Examples
- Data Validation Checks in Excel: Rules and Examples
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- Excel VBA Copy and Paste Formatting Without Changing ValuesTo copy formatting with Excel VBA without copying cell values or formulas, copy the source range and paste…
- VBA UserForm Guide: Build, Code, and Run Excel FormsA VBA UserForm is a custom dialog you build in Excel to collect information or guide a user…
- VBA Open UserForm on Button Click: Code and Setup GuideTo open an Excel VBA UserForm when a worksheet button is clicked, create a public macro in a…
- Excel VBA UserForm Image: Add, Load, and TroubleshootAn Excel VBA UserForm displays a picture with the Microsoft Forms Image control: add the control in the…
- VBA Convert String to Number: Functions and ExamplesTo convert numeric text to a number in VBA, use a conversion function such as CDbl for decimal…
- Replace Select Case with Scripting.Dictionary in VBA?Yes—replace Select Case with a VBA Scripting.Dictionary when you need to look up a result by key, especially…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.