Fix Excel and Word VBA On Error Handler Not Working
Question details
The VBA code halts execution when encountering an error instead of passing control to the designated On Error handler.

- Product
- Excel and Word
- Device & OS
- not provided
- Scenario
- Running a VBA macro that contains On Error GoTo or On Error Resume Next statements for error handling.
- Observed behavior
- The Visual Basic Editor interrupts the macro and displays a run-time error dialog on the faulty line, completely bypassing the user's programmed error handling logic.
Before altering your editor settings, create a brand-new blank document, add a simple macro with an 'On Error Resume Next' statement, and trigger a deliberate error (like dividing by zero). If it works perfectly in the new file, your original document's VBA project may be corrupted.
Adjust Visual Basic Editor Error Trapping Settings
The most common reason for bypassed error handlers is an incorrect global setting in the VBA editor that forces the compiler to break on every single error.
By default, the Visual Basic Editor is designed to pause execution on unhandled errors only. If this setting was accidentally changed to 'Break on All Errors', your custom error handlers will be ignored entirely.
Open your affected Excel workbook or Word document and press Alt + F11 on your keyboard to launch the Visual Basic Editor (VBE).
In the top menu bar of the editor, click on 'Tools' and select 'Options' from the dropdown menu.
Navigate to the 'General' tab in the Options dialog box. Under the 'Error Trapping' section, change the selection from 'Break on All Errors' to 'Break on Unhandled Errors'.
Click 'OK' to save your settings. Run your macro again to verify that your On Error routines are now successfully capturing the errors.

Export and Re-import Corrupted VBA Modules
If the error trapping settings are correct but the issue persists in one specific file, the document's VBA project might contain underlying corruption.
Clear Compiled VBA Code via Project Properties
Forcing the VBA compiler to discard old, potentially glitched compilation states can resolve stubborn file-specific execution errors.
Experience Stable VBA and Macros with WPS Office
If Microsoft Office repair tools fail to resolve your persistent VBA environment issues, consider switching to WPS Office. It provides a highly stable, built-in macro editor designed to handle your complex automation tasks without missing a beat.
- 1. Download and Install: Visit the official WPS Office website to download the free installer and follow the quick setup wizard.
- 2. Open Your Macro File: Launch WPS Spreadsheet or Writer and open your existing .xlsm or .docm file directly.
- 3. Enable Macros and Run: Click 'Enable Macros' on the security prompt, press Alt + F11 to view your code, and run your automation tasks smoothly.

Frequently Asked Questions
Why does my VBA code ignore On Error Resume Next?
This almost always happens when the Visual Basic Editor's Error Trapping option is set to 'Break on All Errors'. Adjusting it to 'Break on Unhandled Errors' via Tools > Options > General will restore normal error handler functionality.
How do I know if my Excel workbook's VBA code is corrupted?
If you write a simple macro with an error handler in a brand-new, blank workbook and it works perfectly, but the exact same code fails in your current file, the original workbook's VBA project is likely corrupted.
Can third-party COM add-ins interfere with VBA execution?
Yes, incompatible third-party COM or Excel add-ins can disrupt the VBA compiler's state. You can diagnose this by launching Excel or Word in Safe Mode, or manually disabling add-ins one by one via File > Options > Add-ins.
Will repairing Microsoft Office fix my VBA editor settings?
Office repairs (both Quick and Online) typically fix corrupted program files and registry keys, but they may not reset user-configured preferences in the Visual Basic Editor like the Error Trapping state.




