How to Enable Macros in Excel
In this article
You can enable macros by opening the Trust Center, navigating to the Macro Settings option, and selecting "Enable All Macros" or "Disable All Macros with Notification." This allows Excel to run VBA scripts that automate repetitive tasks, but it also exposes your workbook to potential security risks. Before proceeding, ensure you trust the source of the file, as macros are a common vector for malware.
What You'll Need
- A computer running a recent version of Microsoft Excel (2010, 2013, 2016, 2019, 365, or Excel for Mac).
- Administrative access to the computer if the setting is locked down by your IT department.
- A specific Excel file (.xlsx or .xlsm) containing the macro code you wish to run.
Step-by-Step
- Open Excel and Navigate to the Trust Center: Launch Microsoft Excel. Click on the File tab located in the top-left corner of the window. In the sidebar that appears, click on Options at the very bottom.
- Access the Trust Center Settings: In the Excel Options dialog box, look for the Trust Center category on the left-hand sidebar. Click on it to select it, and then click the Trust Center Settings button on the right side of the window.
- Select Macro Settings: The Trust Center window will open. Select the Macro Settings category from the list on the left. This is where Excel controls how it handles files containing Visual Basic for Applications (VBA) code.
- Choose the Security Level: You will now see a list of options on the right side. The options generally available are:
- Disable All Macros without Notification: All macros are blocked. If a file contains macros, Excel opens it but leaves them inactive and displays a yellow security bar at the top warning you.
- Disable All Macros with Notification: This is the default setting. Similar to the option above, macros are disabled, but Excel notifies you with a security bar when a file contains them, giving you the option to enable them.
- Disable All Macros except digitally signed macros: Macros are disabled unless they are signed by a trusted publisher. This requires you to have a digital certificate set up beforehand.
- Enable All Macros: This is the setting required to run untrusted or unsigned macros. Select this option.
- Confirm the Change: Click OK to apply the new security setting. You will be returned to the Excel Options window. Click OK once more to close it entirely.
- Verify the Setting: The macro setting applies to all future Excel sessions. To confirm the change has taken effect, open a new Excel workbook and save it as an Excel Macro-Enabled Workbook (.xlsm). Try to insert a simple macro or run a VBA script. You should no longer see the security warning, and the code should execute.
Common Mistakes
- Saving the file in the wrong format: You cannot run macros in a standard .xlsx file. You must explicitly save the file as an .xlsm (Excel Macro-Enabled Workbook). If you save it as .xlsx, Excel will strip out the VBA code automatically.
- Ignoring the security warning: When opening a file that contains macros, Excel will display a warning bar at the top of the window. Clicking Enable Content is the only way to run the code. Simply clicking away or closing the bar will leave the macros dead.
- Assuming "Trust Center" is the same as the file: The Trust Center settings control the application globally. They do not apply to specific files you open. You must change the setting in Options for it to work for every workbook.
Tips
- Use the "Disable All Macros with Notification" setting: While "Enable All Macros" is convenient for testing personal files, it is risky for business use. The safer alternative is to keep the default setting and simply click Enable Content when you know the source is safe.
- Check the file source: Never enable macros from an email attachment, a downloaded file from an unknown website, or a file sent by a stranger. Malicious macros are a primary method of distributing ransomware and viruses.
- Enable for specific files only: If you have a mix of trusted and untrusted files, consider creating a separate Excel file that contains only the macros you use. You can then disable macros globally and enable them only for this specific file.
Troubleshooting
If you have enabled macros but they still fail to run, check the following.
- The macros are grayed out: If you see the macro names in the Developer tab but cannot click them, the workbook is likely protected. Go to the Developer tab and click Protect Workbook Structure (if active) or check if the VBA editor is locked.
- Excel crashes on opening: If the application crashes immediately upon opening a file, the macro code likely contains a syntax error or a malicious command. Do not run the file. Delete it immediately.
- Changes are not saving: If you edit a macro but the file does not update, ensure you are editing the correct module in the VBA editor. Macros are tied to specific worksheets or modules and may not auto-update if the reference is lost.
- File is saved as .xlsx but has macros: Excel automatically removes macros when you save a file with that extension. You must ensure the Save As dialog box is set to Excel Macro-Enabled Workbook (*.xlsm).
Frequently Asked Questions
Is it safe to enable macros?
Enabling macros is generally safe for files you have created yourself or received from a trusted source. However, it is unsafe for files from unknown sources, as malicious code can be hidden inside macros to damage your computer or steal data.
Do I need to enable macros every time I open a file?
If you have set the Trust Center to Disable All Macros with Notification, you must click Enable Content every time you open a file containing macros. If you set it to Enable All Macros, you will not be prompted again.
Where are macros stored in Excel?
Macros are stored in the VBA (Visual Basic for Applications) editor, which you can access by pressing Alt + F11. They are associated with the specific workbook in which they were created.
Can I run macros on Excel for Mac?
Yes, the process is similar. You access the Trust Center via Excel > Preferences > Trust Center. However, some older macros may not be compatible with the Mac version of Excel due to platform differences.
What is the difference between a .xlsx and an .xlsm file?
An .xlsx file is a standard spreadsheet that cannot contain code. An .xlsm file is a macro-enabled workbook, meaning it contains VBA scripts and can run automated tasks.