To run macros in Excel for Microsoft 365 on Windows, open a trusted macro-enabled workbook, select Enable Content if Excel shows a security warning, then choose Developer > Macros and run the macro you need. To view or edit its VBA code instead, press Alt+F11. Only enable macros in files you trust: VBA can make changes to files and data.
What You’ll Need
- A desktop version of Excel. Excel for the web can open a workbook containing VBA, but it cannot run or edit VBA macros.
- A workbook that contains macros, usually saved as
.xlsmor.xlsb. Older.xlsworkbooks can also contain macros. A standard.xlsxfile cannot store VBA macros. - Confidence that the file and its source are trustworthy. If the workbook came from someone you do not know, or you cannot verify what it does, do not enable its macros.
Step-by-Step
- Check the workbook and its source. Confirm who sent the file and why it needs macros. If you expected a macro-enabled workbook, check that its name ends in
.xlsm,.xlsb, or.xls. An.xlsxfile may contain formulas and data, but it cannot contain VBA macros. Do not change an extension by renaming the file; that does not convert its contents or add macros. - Open the workbook in the Excel desktop app. In Windows, open Excel and use File > Open to browse to the workbook, or open it from File Explorer. If it opens in a browser, select the option to open it in the desktop app. Excel for the web does not run VBA, so enabling macros in the browser is not an option.
- Handle Protected View separately from macros. For a file Excel considers potentially unsafe, a yellow Protected View bar may appear. If you have verified the source and want to use the workbook, select Enable Editing. This only allows editing; it does not necessarily enable macros. Read any subsequent security warning and enable content only if you trust the file.
- Enable content for this workbook if Excel offers the prompt. A yellow security bar may say that macros have been disabled and show an Enable Content button. Select it only for a file you trust. Excel may ask you to confirm that the workbook is a trusted document. After approval, the workbook’s macros can run during that session, subject to your organization’s security settings.
- If macros are blocked because the file came from the internet, verify it before unblocking. Close Excel. In File Explorer, right-click the file and choose Properties. On the General tab, look for an Unblock checkbox or button near the bottom. If it is present and you have independently confirmed the file is safe, select it, choose Apply, then OK, and reopen the workbook. This removes a Windows security marker; it does not inspect or repair the macro. If Unblock is not shown, do not try to work around your organization’s security policy.
- Run a particular macro. In Excel, select Developer > Macros, click the macro name in the list, then select Run. If the Developer tab is not visible, you can use View > Macros > View Macros instead. Check the macro name and workbook selection carefully, especially if several workbooks are open. Some macros are designed to run only from a particular sheet or after you select specific cells.
- Open the VBA editor to inspect or change code. Press Alt+F11 on Windows, or select Developer > Visual Basic. In the editor’s Project pane, find your workbook, expand its project, and open a module or a sheet or workbook object to view its code. A password-protected VBA project may not let you see the code. Do not treat an unfamiliar macro as safe just because the editor opens.
- Show the Developer tab if you need it regularly. In Excel for Windows, choose File > Options > Customize Ribbon, check Developer in the Main Tabs list, and select OK. For the VBA editor, the Windows shortcut is Alt+F11. On a Mac, use Tools > Macro > Visual Basic Editor or the Developer tab if it is displayed; depending on the keyboard, the shortcut may require Option+F11 or Fn+Option+F11.
- Save a copy before running a macro that changes data. Use File > Save As to make a backup, and keep the original unchanged. Macros can overwrite cells, delete sheets, or alter files, and Excel’s Ctrl+Z undo command cannot reverse actions performed by a macro. If you need to preserve VBA when saving a workbook, select Excel Macro-Enabled Workbook (*.xlsm) as the file type.
Common Mistakes
- Confusing editing with enabling macros. Selecting Enable Editing in Protected View does not necessarily permit VBA to run. Look for a separate macro security message and Enable Content button.
- Expecting an .xlsx file to contain VBA. The format does not preserve VBA code. If you have a legitimate source file with macros, save it in a macro-enabled format; do not assume changing the file extension will restore missing code.
- Turning on all macros to fix one workbook. The Trust Center has settings that can affect every workbook you open. Enabling all macros globally makes it easier for harmful code to run from other files. Prefer the workbook-specific prompt when available.
- Trusting a file because it arrived by email or looks familiar. A familiar name, logo, or sender display name is not proof that the workbook is safe. Confirm unexpected attachments with the sender through a separate channel.
- Assuming the Developer tab is required to run macros. The tab is convenient but optional: View > Macros > View Macros provides another route in Windows Excel.
Tips
- Prefer the least-permissive setting. If Excel asks whether to enable content for a specific trusted workbook, use that prompt rather than changing a setting that affects all files. If you must review settings, go to File > Options > Trust Center > Trust Center Settings > Macro Settings. Disable VBA macros with notification is generally safer than enabling all VBA macros; your organization may control or lock these options.
- Use a trusted location only for files you control. You can review locations through File > Options > Trust Center > Trust Center Settings > Trusted Locations. Files in a trusted location may be treated differently by Excel’s security checks. Do not add a broad folder such as Downloads or a shared folder that other people can change just to avoid warnings.
- Ask what the macro is meant to do. A legitimate workbook owner should be able to explain why VBA is needed, what data it reads or changes, and whether the file will contact other systems. If the code is available, inspect it or ask a qualified IT person to review it before running it.
- Expect some Windows-specific code not to work on a Mac. Excel for Mac supports many VBA macros, but code that depends on Windows features, ActiveX controls, or Windows-only file paths may fail. The workbook’s author may need to adapt the code for Mac.
- Keep the original file and a clean backup. Save a separate working copy before running an unfamiliar process. If a macro produces unexpected results, close the copy without saving and reopen the original, if you still have it.
Troubleshooting
The Enable Content button is missing. First check whether the workbook is an .xlsm, .xlsb, or .xls file and whether it actually contains macros. If the file was downloaded, Excel may block VBA from internet-marked files without offering the usual prompt. Verify its source, then check for the Windows Unblock option described above. If the file is managed by work or school, contact IT rather than changing security settings yourself.
Macro settings are grayed out or the warning says an administrator blocked macros. Your Microsoft 365 administrator may enforce a policy, or a security feature may block macros from files marked as coming from the internet. Do not try to bypass the restriction. Ask IT whether the file is approved and what supported process to use. A setting in Trust Center may be unavailable when managed by policy.
The Macros list is empty or the macro will not run. Confirm that the correct workbook is active and that it is saved in a macro-capable format. The macro might be stored in another open workbook, be assigned to a button, or require a particular sheet or selection. In the VBA editor, check whether the project is present and whether its code is in a standard module. Some procedures, such as event-driven macros, do not appear in the ordinary Macros list because they run in response to an action.
The macro runs but reports an error or does nothing. The code may rely on missing files, a particular folder path, disabled references, or Windows-only components. Note the exact error message and the step that triggers it; share that information with the workbook’s author or your support team. Avoid repeatedly running a macro that changes data while trying to diagnose it. Restore your backup first if the workbook has been altered unexpectedly.
The workbook opens in Excel for the web. Choose the option to open it in the desktop app. The web version can preserve a workbook containing VBA, but VBA macros cannot run there. If you do not have desktop Excel, ask the file owner for a non-macro workflow or another supported way to access the data.
Frequently Asked Questions
How do I open the VBA editor in Excel?
On Windows, press Alt+F11, or select Developer > Visual Basic. On a Mac, use Tools > Macro > Visual Basic Editor or the Developer tab. You can inspect code only if the VBA project is not locked.
How do I run a macro without the Developer tab?
In Windows Excel, select View > Macros > View Macros, choose the macro, and select Run. You still need permission for macros to run, and the workbook must contain a macro.
Is it safe to enable macros in Excel?
It depends on the file. A macro can change workbook data and perform other actions. Enable it only when you trust the source and understand why it is needed. Do not enable macros in unexpected attachments or files whose origin you cannot verify.
Can I open and run Excel macros online?
You can open a VBA workbook in Excel for the web, but the web app does not run or edit VBA macros. Use the desktop version of Excel for VBA, or ask for an alternative if desktop Excel is unavailable.
Why does Excel keep disabling macros?
Excel may disable them by default as a security measure, block files marked as downloaded from the internet, or follow a policy set by your organization. Check the warning and file source; do not switch on all macros to suppress the warning.
Can I undo a macro with Ctrl+Z?
No. Excel’s undo history does not reverse actions performed by VBA. Save a separate copy before running a macro that may change data, and restore that copy if something goes wrong.
Related
- How to Insert a Line Break in Word Without a New Paragraph
- How to Insert a Blank Line Before a Table in Microsoft Word
- How to Open an IQY File in Excel and Load Web Data
Try it: the Column Letter to Number: aA is 27, XFD is 16,384. Converts both ways.
More in VBA & macros
- VBA Delete Row Based on Cell Value in ExcelTo delete Excel rows when a cell contains a chosen value, loop through the worksheet from the bottom…
- VBA Split Function: How to Split Text into an ArrayIn VBA, use Split(text, delimiter) to break a string wherever a chosen delimiter appears; the result is an…
- Excel VBA AutoFilter Array: Filter Multiple ValuesTo filter a column for several exact values with Excel VBA, pass an array to Criteria1 and set…
- Excel VBA Date Number Format: How to Set ItIn Excel VBA, format a cell or range as a date by setting its NumberFormat property, for example:…
- VBA Pivot Tables: Create, Refresh, and Set Fields EasilyYes. In Excel for Microsoft 365 on Windows, VBA can create a PivotTable, assign its row, column, filter,…
- Chrome Macro Recorder: Built-In Tools and ExtensionsChrome does not include a general-purpose macro recorder for automating any website, but it does have a built-in…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.