Office 365 VBA usually stops working because macros are disabled by default security settings or the file is saved in a format that does not support code. To fix this immediately, ensure your file is saved as an .xlsm (Excel Macro-Enabled Workbook) and change your Trust Center settings to enable macros. Note that menu labels may differ slightly depending on your specific version of Office 365, your operating system, or your regional settings.
What You'll Need
- A computer with a licensed installation of Microsoft Office 365.
- Administrative privileges on the PC to change security settings if they are locked by a system administrator.
- The specific file containing the VBA code you are trying to run.
- A backup copy of your workbook before making significant changes to security settings.
Step-by-Step
- Verify the File Extension
VBA code cannot be stored in a standard .xlsx file. If you save a workbook containing macros as a standard workbook, Excel will strip the code out entirely upon saving. Check the file extension in your folder. If it ends in .xlsx, the code is gone. You must save the file as an .xlsm (Excel Macro-Enabled Workbook) or .xlsb (Excel Binary Workbook). To do this, go to File > Save As and select the Macro-Enabled Workbook option from the dropdown menu.
- Enable the Developer Tab
By default, the tools needed to manage VBA are hidden. To see them, 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. You will now see a Developer tab at the top of your screen, which provides direct access to the Visual Basic Editor, Macro list, and security settings.
- Adjust Trust Center Macro Settings
Office 365 has strict security defaults to prevent malicious code from running. Go to the Developer tab and click on Macro Security. This opens the Trust Center. Under Macro Settings, you will see several options. For testing and internal use, select "Disable all macros with notification." This is the safest functional setting because it prevents macros from running automatically but gives you a yellow "Enable Content" bar at the top of the screen when you open a file. If you select "Enable all macros," you remove this safety layer, which is generally not recommended for files downloaded from the internet.
- Unblock Files from the Internet
Microsoft recently introduced a security feature called "Mark of the Web." If you downloaded the file from an email or a cloud drive, Office may block macros regardless of your Trust Center settings. To fix this, close the file. Locate the file in Windows File Explorer, right-click it, 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." Check the box labeled Unblock and click Apply, then OK. Now open the file again.
- Add a Trusted Location
If you have a specific folder where you keep all your VBA-enabled tools, you can tell Office to trust that entire folder. Go to File > Options > Trust Center > Trust Center Settings > Trusted Locations. Click Add new location. Browse to the folder where your files are stored and check the box "Subfolders of this location are also trusted." Once saved, any file placed in this folder will bypass the "Enable Content" warning and run macros immediately.
- Check for VBA Component Installation
In some corporate or "slimmed down" installations of Office 365, the Visual Basic for Applications (VBA) component is not installed. To check this, press Alt + F11. If nothing happens or you receive an error stating the feature is not available, you may need to repair your Office installation. Go to the Windows Control Panel > Programs and Features. Find Microsoft 365, right-click it, select Change, and choose "Online Repair." This will ensure all components, including the VBA engine, are correctly installed.
Common Mistakes
One of the most frequent errors is attempting to run VBA in the web version of Office 365 (Excel Online). VBA is a desktop-only technology; it does not run in a web browser. If you open an .xlsm file in a browser, you can edit the data, but the macros will not execute. You must click "Open in Desktop App" to use the code.
Another common mistake is ignoring the "Security Warning" bar. Users often overlook the yellow bar that appears just below the ribbon when a file is first opened. If you do not click "Enable Content," the VBA code remains dormant, and any buttons or shortcuts linked to macros will simply do nothing when clicked.
Users also frequently forget to check if their code is located in the correct module. VBA code intended to run as a general macro must be placed in a standard Module (Insert > Module), not in the "ThisWorkbook" or "Sheet" objects. Code placed in sheet objects is usually intended for Event procedures (like automatically running code when a cell changes) and will not appear in the standard Macro list.
Tips
To make your VBA tools more reliable, use the "Trusted Documents" feature. Once you have enabled content for a file once, Office remembers that you trust that specific file. This means you don't have to lower your global security settings to "Enable All Macros," which keeps your system protected from other potentially harmful files.
When writing or debugging code, use the F8 key in the Visual Basic Editor. This allows you to step through your code one line at a time. This is the most effective way to find exactly which line is causing a crash or why a specific condition is not being met.
Always use Option Explicit at the very top of your modules. To enable this automatically, go to Tools > Options in the VBA editor and check "Require Variable Declaration." This forces you to define every variable, which prevents 90% of common bugs caused by typos in variable names.
Troubleshooting
If the macros are enabled and the file is unblocked but the code still won't run, check for "Compile Errors." In the VBA editor, go to the Debug menu and select Compile VBAProject. If there is a syntax error or a missing reference, Excel will highlight the exact line of code that is broken. Often, VBA stops working because a reference to an external library (like a specific version of Outlook or a system DLL) is missing. Check Tools > References to see if any items are marked as "MISSING." If so, uncheck them or update them to the current version installed on your machine.
If your macros are causing Excel to freeze or crash without an error message, check for infinite loops. A common culprit is a "Worksheet_Change" event that modifies the sheet, which then triggers the "Worksheet_Change" event again. To fix this, use the command "Application.EnableEvents = False" at the start of your code and set it back to "True" at the end.
If you are in a corporate environment and the Macro Security settings are greyed out, your IT department has likely implemented a Group Policy (GPO). In this case, you cannot change the settings yourself. You will need to contact your system administrator to request that your specific folder be added to the "Trusted Locations" list via the registry or group policy.
Frequently Asked Questions
Can I run VBA macros on a Mac?
Yes, but with limitations. Most VBA code works on macOS, but commands that rely on Windows-specific file paths (like C:\Users\...) or Windows API calls will fail. You must use Mac-compatible path separators and avoid Windows-only libraries.
Why did my macros disappear after I saved the file?
This happens if you saved the file as a .xlsx workbook. Standard Excel workbooks cannot store macros. You must save as .xlsm or .xlsb to preserve your code. Once saved as .xlsx, the code is permanently deleted and cannot be recovered unless you have a backup.
What is the difference between VBA and Office Scripts?
VBA is the traditional language for desktop Office apps. Office Scripts is a newer, TypeScript-based language designed specifically for the web version of Office 365. Office Scripts can run in the browser and be automated via Power Automate, whereas VBA requires the desktop application.
Does enabling macros make my computer vulnerable to viruses?
Yes, if you enable macros for files from unknown sources. Macros are powerful scripts that can modify files, delete data, or download software. Always keep your settings on "Disable all macros with notification" and only enable content for files you created or received from a trusted source.
Why is my VBA code running slowly in Office 365?
VBA often slows down because it updates the screen and calculates formulas after every single change. You can significantly speed up your code by adding "Application.ScreenUpdating = False" and "Application.Calculation = xlCalculationManual" at the beginning of your macro, and turning them back on at the end.