How to Record and Save a Macro in Excel
In this article
To record and save a macro in Excel, you need the Developer tab visible, then use Record Macro to capture your actions, stop recording, and save the workbook as an Excel Macro-Enabled Workbook (.xlsm). Macros are stored in the workbook or in your Personal Macro Workbook if you want them available in every file. The steps below walk through the entire process, from enabling the Developer tab to running your saved macro later.
What You'll Need
- Microsoft Excel for Windows or Mac (the Developer tab is available in both; the exact labels can differ slightly by version and region).
- A workbook where you want to record the macro. If you plan to keep the macro, you will save it as an .xlsm file.
- Macros enabled in Excel's Trust Center settings. By default, Excel disables macros with a security warning; you may need to enable them for the file you trust.
Step-by-Step
- Show the Developer tab. On Windows, go to File > Options > Customize Ribbon, then tick Developer in the right-hand list and click OK. On Mac, go to Excel > Preferences > Ribbon & Toolbar, tick Developer, and close the window. The Developer tab now appears on the ribbon.
- Decide where to save the macro. Click Developer > Record Macro. In the dialog, give the macro a name (no spaces; use underscores if needed), optionally assign a keyboard shortcut (Ctrl+Shift+letter), and choose where to store it: “This Workbook” for use only in the current file, or “Personal Macro Workbook” to make it available in all workbooks on that computer. Click OK.
- Perform the actions you want to record. Excel captures every click and keystroke in the active workbook. Keep the steps simple and avoid switching to other applications, because the recorder only tracks Excel actions. If you make a mistake, you can stop and start over; the recorder does not edit out errors.
- Stop recording. Click Developer > Stop Recording. The macro is now saved in the location you chose.
- Save the workbook in the correct format. If you stored the macro in “This Workbook”, save the file as Excel Macro-Enabled Workbook (*.xlsm): File > Save As, choose that format from the dropdown, and click Save. If you used the Personal Macro Workbook, Excel saves it automatically when you exit; you may be prompted to confirm.
- Test the macro. Press the shortcut you assigned, or go to Developer > Macros, select the macro name, and click Run. Watch what happens and confirm it performs the intended actions.
- Edit or delete if needed. To change the macro, use Developer > Macros > Edit to open the VBA editor. To remove it, select it in the Macros dialog and click Delete. Deleting a macro cannot be undone, so keep a backup copy of the workbook first.
Common Mistakes
- Saving as a regular .xlsx file. Macros are stripped out when you save in the default format. Always use .xlsm for workbooks that contain macros.
- Recording with the wrong cell selected. The macro records the exact cell references you use. If you start recording on cell A1 but later run the macro from cell D10, it will still act on A1. Use relative references (Developer > Use Relative References) if you want the macro to work from the current cell.
- Including unnecessary steps. Every scroll, selection, and sheet switch is recorded. Extra actions make the macro slower and more likely to fail. Plan the steps before you hit Record.
- Forgetting to stop recording. If you leave the recorder running, later edits get appended to the macro. Always click Stop Recording when finished.
- Ignoring security warnings. Excel blocks macros from untrusted locations by default. If the macro does not run, check the yellow security bar and enable content only for files you trust.
Tips
- Write down the steps on paper first; a clear sequence records more reliably than improvising.
- Use keyboard shortcuts during recording instead of mouse clicks where possible; they are less error-prone and faster.
- Name macros descriptively (e.g., FormatReport) so you can find them later in the Macros list.
- Test the macro on a copy of your data before using it on important files.
- If you need the macro in many workbooks, store it in the Personal Macro Workbook and assign a shortcut.
- Remember that macros cannot undo; save your file before running a new macro so you can revert if something goes wrong.
Troubleshooting
- The Developer tab is missing. Follow the Customize Ribbon steps above; on Mac, check Ribbon & Toolbar preferences. If you still do not see it, your Excel version may not support macros (e.g., some web or mobile versions), so use the desktop app.
- The macro does not appear in the list. Make sure you saved the workbook as .xlsm and that the macro was stored in “This Workbook” or the Personal Macro Workbook. If you saved as .xlsx, the macro was discarded; re-record and save correctly.
- Excel shows a security warning and disables macros. Click “Enable Content” only if you trust the file's source. To change default behavior, go to File > Options > Trust Center > Trust Center Settings > Macro Settings, but be cautious: enabling all macros is a security risk.
- The macro runs but does the wrong thing. Edit the macro in the VBA editor to review the recorded steps. Common fixes include removing extra selections or changing hard-coded cell references to relative ones.
- You get a “Cannot run the macro” error. The macro may have been deleted, the workbook may be read-only, or the macro name may have changed. Check the Macros dialog and ensure the workbook is not protected.
- The shortcut does not work. Another macro or Excel feature may already use that key combination. Reassign the shortcut in the Record Macro dialog or run the macro from the Macros list.
Frequently Asked Questions
Can I record a macro that works in any workbook?
Yes. When you start recording, choose “Personal Macro Workbook” in the “Store macro in” dropdown. The macro will be available in all workbooks on that computer. Note that the Personal Macro Workbook is hidden; you can unhide it via View > Unhide if you need to edit it.
Why does Excel say my macro is disabled?
Excel's Trust Center blocks macros by default for files from the internet or untrusted locations. Look for a yellow security bar and click Enable Content only if you trust the file. You can also add the file's folder to Trusted Locations in Trust Center settings.
Can I edit a macro after recording it?
Yes. Go to Developer > Macros, select the macro, and click Edit. This opens the VBA editor where you can change the recorded code. Basic edits are possible, but VBA knowledge helps for complex changes.
Do macros work in Excel for the web or mobile?
No, Excel for the web and the mobile apps do not support recording or running VBA macros. You need the desktop version of Excel for Windows or Mac.
What happens if I save a macro-enabled workbook as .xlsx?
Excel warns you that macros will be removed. If you proceed, the macro code is deleted from that file. Always keep a backup copy in .xlsm format if you need the macros.
Can I undo a macro's actions?
No, macros cannot be undone with Ctrl+Z. Save your workbook before running a macro so you can close without saving or revert to the saved version if something goes wrong.