Restore Excel EnableEvents After a VBA Macro Error
Question details
Ensure Excel application settings are restored when a VBA macro fails or is interrupted.

- Product
- Microsoft Excel VBA
- Device & OS
- not provided
- Scenario
- A macro disables EnableEvents and other application settings while it runs.
- Observed behavior
- If the macro stops before restoring EnableEvents, events such as Worksheet_Change do not run.
Open the affected workbook and use Developer > Visual Basic to inspect the macro that changes application settings. Check whether events are already disabled before deciding whether to restore the previous setting or explicitly turn events on.
Restore the previous settings with a VBA cleanup section
Use an error handler and a shared cleanup section to restore settings after normal completion or a handled error.
Save the original settings before changing them. The cleanup section restores those values rather than assuming they were initially True.
In Excel, select Developer > Visual Basic, then open the module containing the procedure that changes EnableEvents.
Adapt this structure to your procedure, placing your existing macro code where indicated: Sub RunWithCleanup() Dim oldEvents As Boolean Dim oldAlerts As Boolean Dim errorNumber As Long Dim errorDescription As String oldEvents = Application.EnableEvents oldAlerts = Application.DisplayAlerts On Error GoTo RecoverFromError Application.EnableEvents = False Application.DisplayAlerts = False ' Place your macro code here. CleanUp: On Error GoTo 0 Application.EnableEvents = oldEvents Application.DisplayAlerts = oldAlerts If errorNumber <> 0 Then MsgBox "Error " & errorNumber & ": " & errorDescription End If Exit Sub RecoverFromError: errorNumber = Err.Number errorDescription = Err.Description Resume CleanUp End Sub
Run the procedure from the VBA editor and test an error path. After the message appears, check Application.EnableEvents and Application.DisplayAlerts in the Immediate window.

Re-enable Excel events from the Immediate window
Use this recovery method when a stopped macro has already left events disabled.
Work with Excel spreadsheets in WPS Office
WPS Office is a free, lightweight alternative with a familiar interface and Excel format compatibility for a smooth move between spreadsheet tools. It does not repair Excel VBA settings, so verify macro compatibility before migrating a macro-enabled workbook.

Frequently Asked Questions
Why doesn't Worksheet_Change turn events back on?
Worksheet_Change cannot run while Application.EnableEvents is False. Use the Immediate window to set Application.EnableEvents = True, or restore the setting in the macro that disabled it.
How can I check whether Excel events are enabled?
In the Visual Basic editor, select View > Immediate Window, enter ? Application.EnableEvents, and press Enter. The result is True or False.
Should I always set EnableEvents to True in cleanup?
Not necessarily. Saving Application.EnableEvents before changing it and restoring that value preserves the setting that existed before the macro ran. Set it to True manually when you specifically want to re-enable events.
Does On Error Resume Next restore application settings?
No. It suppresses errors and continues execution; it does not restore settings. Use a cleanup section to restore them, and use On Error GoTo 0 to disable the current error handler when appropriate.




