April 6, 2010

Disable Excel events

How to accelerate the refresh of data connections in a large Excel workbook which has macros triggered by events: disable the events before refreshing the connections, then re-enable the events.

Sub refresh_data()
'disables events, updates data connections, then enables events.

Application.EnableEvents = False
'code to execute with events disabled:
ActiveWorkbook.RefreshAll
Application.EnableEvents = True

End Sub