To save a new macro in Excel, you record or write the macro, then save the workbook as an Excel Macro-Enabled Workbook (.xlsm) or in the Personal Macro Workbook if you want it available in every file. Macros written in the default .xlsx format are discarded when you close the file, so the file type is the step people most often miss. This guide walks through recording a macro, saving it correctly, and making it easy to run again.
What You'll Need
- Excel for Windows or Excel for Mac (the Developer tab and Visual Basic Editor are not available in Excel for the web).
- The Developer tab visible on the ribbon. If it is missing, enable it via File > Options > Customize Ribbon and tick Developer, or on Mac via Excel > Preferences > Ribbon & Toolbar.
- A workbook you are allowed to modify. If macros are blocked by your organisation's policy, ask your IT administrator before proceeding.
Step-by-Step
- Open the workbook where the macro should live. If you want the macro available in every workbook, skip to the Personal Macro Workbook note in the Tips section; otherwise use the file you are working in.
- Show the Developer tab. Go to File > Options > Customize Ribbon, tick Developer in the right-hand list, and click OK. On Mac, open Excel > Preferences > Ribbon & Toolbar and tick Developer.
- Click Developer > Record Macro. A small dialog appears.
- Name the macro. Use a name with no spaces (underscores are fine), starting with a letter. Names like FormatReport or CleanData are easier to find later than Macro1.
- Choose where to store it. Use "This Workbook" for a macro tied to the current file, or "Personal Macro Workbook" to make it available in every workbook you open on that computer.
- Add a description and a shortcut key if you want one. A shortcut key is optional; if you assign one, avoid combinations Excel already uses (for example Ctrl+C or Ctrl+S).
- Click OK to start recording. Excel now captures your actions.
- Perform the actions you want to automate. Keep them simple and deliberate; every click and keystroke in cells is recorded.
- Click Developer > Stop Recording when finished. The macro is now stored in the workbook's macro list.
- Save the file in a macro-enabled format. Go to File > Save As, open the "Save as type" dropdown, and choose Excel Macro-Enabled Workbook (*.xlsm). Give the file a name and click Save. If you save as .xlsx, Excel warns that macros cannot be saved; choosing to keep .xlsx will strip them.
- Test the macro. Press the shortcut key you assigned, or go to Developer > Macros, select the macro, and click Run. Confirm it does what you expect on a copy of your data first.
- Reopen the file to verify. Close and reopen the .xlsm file. If the macro is still listed under Developer > Macros, it saved correctly.
Common Mistakes
- Saving as .xlsx. This is the most common cause of lost macros. The default format does not store VBA code, and Excel will warn you before discarding it.
- Recording too many actions. Scrolling, selecting cells, and switching sheets all get recorded. Plan the steps before you hit Record Macro.
- Using spaces or special characters in the macro name. Excel rejects names with spaces and names that begin with a number.
- Storing in the wrong place. A macro saved to "This Workbook" will not appear in other files; a macro saved to the Personal Macro Workbook will not travel with the file if you email it.
- Forgetting that macros are disabled by default. When you reopen the file, Excel may show a security warning bar. You must click Enable Content for the macro to run.
Tips
- Use the Relative References button on the Developer tab before recording if you want the macro to work from wherever the cursor is, rather than always starting at the same cell.
- Record a rough version first, then open Developer > Visual Basic to tidy the generated code. The recorder produces verbose code that is rarely efficient.
- Keep a backup copy of any .xlsm file before editing its macros, since a corrupted macro workbook can be difficult to recover.
- If you need the macro in every workbook on this computer, store it in the Personal Macro Workbook. It is hidden by default; unhide it via View > Unhide if you need to edit the code.
- Name macros with a consistent prefix (for example rpt_ or data_) so they sort together in the macro list.
Troubleshooting
- The Developer tab is missing. Enable it through File > Options > Customize Ribbon (Windows) or Excel > Preferences > Ribbon & Toolbar (Mac). If the option is greyed out, your organisation may restrict it.
- Excel says macros are disabled. Look for the yellow security bar under the ribbon and click Enable Content. If your organisation blocks macros entirely, you will need to ask IT; do not attempt to bypass the policy.
- The macro is not in the list after reopening. The file was almost certainly saved as .xlsx. Use Save As and choose .xlsm, then re-record or re-import the macro.
- The macro runs but does the wrong thing. Open Developer > Visual Basic, review the recorded steps, and delete lines that select cells or scroll unnecessarily. Re-test on a copy of your data.
- The shortcut key does nothing. Another macro or Excel command may already use that combination. Reassign the shortcut in Developer > Macros > Options.
- Excel crashes when running the macro. Save your work, close Excel, reopen the file, and try again. If it repeats, disable the macro and inspect the code for references to sheets or ranges that no longer exist.
Frequently Asked Questions
Can I save a macro in a normal .xlsx file?
No. The .xlsx format does not store VBA code. You must save as .xlsm (Excel Macro-Enabled Workbook) or store the macro in the Personal Macro Workbook.
Where is the Personal Macro Workbook saved?
Excel stores it as a hidden file named Personal.xlsb in your Excel startup folder. You can unhide it via View > Unhide to edit its macros.
Will the macro work if I email the file to someone else?
Only if you send the .xlsm file and the recipient enables macros. Macros stored in the Personal Macro Workbook do not travel with the file.
Can I edit a macro after recording it?
Yes. Go to Developer > Visual Basic, find the module containing the macro, and edit the code directly. Save the workbook afterwards.
Why does Excel warn me about macros when I open the file?
Excel disables macros by default for security. The warning bar lets you enable content for that file. Only enable macros in files you trust.
Do macros work in Excel for the web?
No. Recording and editing VBA macros requires the desktop version of Excel for Windows or Mac.