Excel 365 VBA macros often stop working due to security settings, corrupted modules, or add-in conflicts — not because the feature is broken. The solution is usually quick: enable macros, check for errors in the code, and reset trusted locations. This guide fixes the most common causes without reinstalling Excel.

What You'll Need

  • A Windows PC or Mac with Microsoft Excel 365 installed
  • Administrative rights to change Excel settings (Windows)
  • The workbook containing the VBA code (preferably saved as .xlsm)
  • Access to the Developer tab in Excel’s ribbon

Step-by-Step

  1. Open the Excel workbook that contains the VBA code. If you see a security warning bar at the top saying "Macros have been disabled," click "Enable Content" — this is the most common fix. If the bar doesn’t appear, proceed to the next steps.
  2. Press Alt+F11 to open the Visual Basic for Applications editor. If nothing opens or Excel freezes, restart Excel in Safe Mode: close Excel, press Windows+R, type excel /safe, then press Enter. Try opening the file again and press Alt+F11.
  3. In the VBA editor, check the Project Explorer pane (usually on the left). If it’s not visible, press Ctrl+R. Look for your workbook under VBAProject. If it’s missing or shows "(Not Responding)", the file may be corrupted — skip to the Troubleshooting section.
  4. Expand the workbook tree and click on any Module or ThisWorkbook. Check for red lines or syntax errors highlighted in the code window. Fix obvious typos, missing End Sub statements, or undefined variables. If you don’t understand the code, do not edit it — proceed to step 5.
  5. Go to Excel’s main window, click the Developer tab. If you don’t see it, right-click the ribbon, select "Customize the Ribbon," and check "Developer" under Main Tabs. Click "Macro Security" and set it to "Enable all macros" temporarily. Click OK. If the option is grayed out, your organization’s Group Policy restricts it — contact your IT admin.
  6. Save the workbook as a Macro-Enabled Workbook (.xlsm). Go to File > Save As, choose "Excel Macro-Enabled Workbook (*.xlsm)" from the file type dropdown, and save. Close and reopen the file.
  7. Test the macro by pressing Alt+F8, selecting the macro name, and clicking "Run." If it runs, the issue was a security or file format problem. If it still fails, check the Immediate Window in the VBA editor: press Ctrl+G, then run the macro again. Any error messages will appear here — note them for troubleshooting.
  8. If the macro still doesn’t run, disable all Excel add-ins. Go to File > Options > Add-ins. At the bottom, select "Excel Add-ins" from the Manage dropdown and click "Go." Uncheck all boxes, click OK, restart Excel, and test the macro again. If it works, re-enable add-ins one at a time to find the conflicting one.
  9. If nothing works, create a new blank workbook. Press Alt+F11, right-click VBAProject, choose "Import File," and select your original .bas or .cls module files. Copy and paste the code manually into new modules. Save this new file as .xlsm. This bypasses hidden corruption in the original file structure.

Common Mistakes

  • Trying to run macros in .xlsx files — they don’t support VBA. Always save as .xlsm.
  • Assuming "Enable Content" is enough — sometimes Trusted Locations or Digital Signatures block execution even after enabling.
  • Editing code without saving the workbook first — changes in the VBA editor are lost if you don’t save the file.
  • Using external references (like other workbooks or network paths) that are broken or unavailable when the macro runs.
  • Running macros on a Mac with Excel 365 — some VBA features (like API calls or shell commands) are not supported on macOS.

Tips

  • Always back up your workbook before editing VBA code — use File > Save As and add "_backup" to the filename.
  • Use Option Explicit at the top of every module to catch undeclared variables — it reduces runtime errors.
  • Sign your macros with a digital certificate if you distribute them — this avoids security warnings for recipients.
  • Keep your VBA code modular: separate functions into dedicated modules for easier debugging.
  • Use Debug.Print statements in your code to log values to the Immediate Window — it helps trace execution flow without breakpoints.
  • Update Excel regularly: Microsoft patches VBA engine bugs in monthly updates. Check via File > Account > Update Options > Update Now.

Troubleshooting

If VBA still doesn’t work after following all steps above:

  1. Check Windows Defender or third-party antivirus software — some block VBA execution. Temporarily disable real-time protection and test. If it works, add Excel.exe to the exclusion list.
  2. Reset Excel’s settings: Close Excel, press Windows+R, type %appdata%\Microsoft\Excel\, and press Enter. Rename the "XLSTART" folder to "XLSTART_old". Restart Excel — this clears custom templates and add-ins.
  3. Repair Office: Go to Windows Settings > Apps > Apps & features, find Microsoft 365, click "Modify," select "Quick Repair," and restart. If that fails, try "Online Repair." This reinstalls core components without losing data.
  4. Test on another computer: If the macro works elsewhere, your Excel install is damaged. If it doesn’t, the code or file is the issue.
  5. Check for conflicting software: Programs like Adobe Acrobat, Citrix, or remote desktop tools sometimes interfere with VBA. Try running Excel in a clean boot environment (msconfig > Services > Hide Microsoft services > Disable all > Restart).
  6. For enterprise users: Ask your IT department to check Group Policy settings under Computer Configuration > Administrative Templates > Microsoft Excel 2016 > Security Settings > Macro Settings. They may enforce "Disable all macros without notification."

Frequently Asked Questions

Why does my VBA code work on one computer but not another?

Different security settings, Excel versions, missing references (like "Microsoft Scripting Runtime"), or operating system differences (Windows vs. Mac) cause this. Always test on the target machine.

Can I run VBA macros on Excel for the web?

No. Excel for the web does not support VBA. You must use the desktop app to create, edit, or run macros.

Why do I get a "Compile Error: Expected: End Sub" message?

You’re missing an End Sub, End Function, or End If statement. Check each procedure in the VBA editor — every block must be properly closed.

Is it safe to enable all macros?

Only if you trust the source of the workbook. Enabling all macros exposes you to malware. Use "Enable macros for trusted locations" instead, and only save files in trusted folders like your Documents directory.

Why does Excel crash when I open a file with VBA?

Corrupted modules or infinite loops in the Auto_Open or Workbook_Open events cause crashes. Open the file in Safe Mode, then disable macros to edit the code safely.

Can I recover VBA code if I accidentally deleted a module?

Yes, if you saved the workbook recently. Excel auto-saves backups in %appdata%\Roaming\Microsoft\Excel\. Search for .xlsm files with "~" in the name — they may contain your code.