VBA & Macro Problems

Restore Excel EnableEvents After a VBA Macro Error

Elise WilliamsElise Williams Nov 27, 2026 871 views

Question details

Ensure Excel application settings are restored when a VBA macro fails or is interrupted.

Restore Excel EnableEvents After a VBA Macro Error
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the macro

In Excel, select Developer > Visual Basic, then open the module containing the procedure that changes EnableEvents.

2
Add an error handler and cleanup section

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

3
Test the cleanup

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.

Restore the previous settings with a VBA cleanup section
Forced stops can bypass cleanup: A VBA Reset, End statement, or forced termination can bypass the cleanup section. If that happens, restore the settings manually in the Immediate window.
Free Microsoft Office alternative

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.

Open and edit compatible Excel spreadsheet filesSupports Microsoft Excel formats including XLSX and XLSMUse a familiar spreadsheet interfaceInstall a free, lightweight office suite
microsoft office alternative - wps office

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.