VBA macros usually stop working in Office 365 because Microsoft has implemented stricter security defaults that block macros in files originating from the internet or untrusted locations. To fix this, you must enable the Developer tab, adjust the Trust Center settings, and specifically "unblock" files that have been flagged by Windows security. This guide covers the necessary configuration changes to restore macro functionality while maintaining a secure environment.
What You'll Need
- A computer running a desktop version of Office 365 (Macros are not supported in Office Online/Web versions).
- Administrative privileges on the PC to change security settings if prompted.
- The specific Excel, Word, or PowerPoint file containing the macros you wish to run.
Step-by-Step
- Enable the Developer Tab: By default, the tools needed to manage VBA are hidden. Right-click any existing tab on the top Ribbon (such as Home or Insert) and select Customize the Ribbon. In the right-hand column, find the checkbox labeled Developer and check it. Click OK. The Developer tab will now appear in your top menu. Note that menu labels may differ slightly depending on your specific Office version or region.
- Verify the File Extension: Macros cannot run in standard file formats. Ensure your file is saved in a macro-enabled format. For Excel, this must be .xlsm or .xlsb. For Word, use .docm. If your file is a .xlsx or .docx, the macros have been stripped out during the save process and cannot be recovered unless you have a backup copy. Go to File > Save As and change the file type to the macro-enabled version if necessary.
- Configure Trust Center Settings: Navigate to the File menu, select Options, and then click Trust Center. Click the Button labeled Trust Center Settings. In the left-hand menu, select Macro Settings. Choose "Disable VBA macros with notification." This is the recommended setting because it prevents macros from running automatically (which protects you from malware) but provides a yellow Message Bar at the top of the screen allowing you to manually enable them for each session.
- Enable Trust Access to the VBA Project Object Model: While still in the Trust Center Settings menu, go to Macro Settings and check the box that says "Trust access to the VBA project object model." This is often required for macros that need to modify other macros or interact with the Office application structure itself.
- Unblock Files from the Internet: If you downloaded the file from an email or a cloud drive, Windows may have applied a "Mark of the Web" block. Close the Office application entirely. Locate the file in your Windows File Explorer. Right-click the file and select Properties. In the General tab, look for a section at the bottom labeled Security that says "This file came from another computer and might be blocked to help protect this computer." Check the box labeled Unblock and click Apply, then OK.
- Create a Trusted Location: To avoid unblocking files individually, you can designate a specific folder on your hard drive as a "safe zone." In the Trust Center Settings menu, select Trusted Locations. Click Add new location. Browse to the folder where you store your macro-enabled files and check the box "Subfolders of this location are also trusted." Click OK. Any file placed in this folder will bypass the security warnings.
- Enable Content via the Message Bar: Open your file. If you see a yellow bar at the top of the document stating "Security Warning: Macros have been disabled," click the Enable Content button. The macros will now be active for this specific session.
Common Mistakes
One of the most frequent errors is attempting to run macros in the web-based version of Office 365. VBA (Visual Basic for Applications) is a desktop-only technology. If you open a .xlsm file in a web browser, the macros will not execute, and you will not see the Developer tab. You must select "Open in Desktop App" to use the automation features.
Another common mistake is saving a macro-enabled workbook as a standard .xlsx file. When you do this, Office displays a warning that the VBA project will be lost. Many users click "Yes" to save anyway, which permanently deletes all the code within that file. Always double-check the file extension before saving.
Users also frequently confuse "Disable all macros without notification" with "Disable all macros with notification." The former silently blocks everything, meaning you will never see the yellow warning bar, and you will assume the macro is broken when it is actually just being suppressed by the security policy.
Finally, some users attempt to enable macros globally by selecting "Enable all macros." This is a significant security risk. If you download a malicious file from the internet, it could execute harmful code the moment you open it without your consent. Always use the "with notification" setting or Trusted Locations instead.
Tips
To make your macros more reliable, avoid using absolute file paths (like C:\Users\Name\Documents\File.xlsx) within your code. Instead, use relative paths or the "ThisWorkbook.Path" property in VBA. This ensures that if you move the folder to another computer or a shared network drive, the macro won't crash due to a "File Not Found" error.
When sharing macro-enabled files with colleagues, send them a short set of instructions on how to "Unblock" the file via the Properties menu. Most users will assume the file is corrupted when they see the security block, but a quick explanation of the Windows security property can save hours of troubleshooting.
Use the "Immediate Window" (Ctrl+G in the VBA editor) to test small snippets of your code without running the entire macro. This allows you to isolate which specific line of code is causing a failure, making the debugging process much faster.
Consider using a dedicated folder for all your automation tools and adding that single folder to the Trusted Locations list. This streamlines your workflow, as you will no longer have to click "Enable Content" every time you open a tool you use daily.
Troubleshooting
If the macros still do not run after following the steps above, first check if your organization has a Group Policy in place. In corporate environments, IT administrators often override local Office settings. If the Macro Settings in the Trust Center are greyed out or cannot be changed, your company has locked these settings for security reasons. You will need to contact your IT department to request a policy exception or a Trusted Location for your specific project.
If you encounter a "Compile Error," the problem is not with Office 365 security, but with the code itself. This often happens when a macro was written for an older version of Office and uses a library (Reference) that is no longer available. Open the VBA Editor (Alt+F11), go to Tools > References, and look for any items marked as "MISSING." Uncheck the missing reference and find the updated version of that library in the list.
If the application freezes when a macro starts, check for infinite loops in your code. A common culprit is a "Worksheet_Change" event that modifies the sheet, which then triggers the "Worksheet_Change" event again. To fix this, add "Application.EnableEvents = False" at the start of your code and "Application.EnableEvents = True" at the end.
If you see a "Runtime Error 1004," this is usually a generic error indicating that VBA cannot find a specific cell, sheet, or file. Verify that the sheet names in your code exactly match the sheet names in your workbook, including spaces and capitalization.
Frequently Asked Questions
Can I run VBA macros on a Mac?
Yes, but with limitations. VBA is supported in Office for Mac, but some Windows-specific commands (like those interacting with the Windows Registry or certain ActiveX controls) will not work. You may need to rewrite parts of the code to be cross-platform.
Do macros work in the Office 365 mobile app?
No. The mobile versions of Excel, Word, and PowerPoint for iOS and Android do not support VBA macros. You can view the data in the file, but the automation will not execute.
What is the difference between VBA and Office Scripts?
VBA is the traditional language for desktop automation. Office Scripts is a newer TypeScript-based language designed specifically for the web version of Office 365 and integration with Power Automate.
Why does my macro work on my PC but not on my coworker's PC?
This is usually due to the "Mark of the Web" block. Your coworker likely needs to right-click the file in File Explorer and select "Unblock" in the Properties menu, or you need to place the file in a folder that is a Trusted Location on their machine.
Is there a way to password protect my VBA code?
Yes. In the VBA Editor, go to Tools > VBAProject Properties, select the Protection tab, check "Lock project for viewing," and enter a password. This prevents others from seeing or editing your logic.
Can a macro be a virus?
Yes, macros can be used to deliver malware. This is why Microsoft blocks them by default. Never enable macros in a file received from an unknown sender or a suspicious source.