I use a function to record the state of the calculation before I start, and reset it to that when I'm done. (There are sometimes where I'm working in manual mode and want to keep it like that.)
Dim xlCalcState As Long
Public Sub Environ_RestoreSettings()
'Macro created 06/11/2005 22:33 by Ken Puls
'Macro Purpose: To restore application properties to user settings
'Restore screen updates, clear statusbar and set
'calculation back to user's initial setting
With Application
.ScreenUpdating = True
.DisplayAlerts = True
.Calculation = xlCalcState
.StatusBar = False
End With
'Set the calculation state variable to 0
xlCalcState = 0
End Sub
Public Sub Environ_SpeedBooster()
'Macro created 06/11/2005 22:29 by Ken Puls
'Macro Purpose: To set application properties to maximize speed
With Application
'Add workbook if necessary to avoid calculation error messages
If .Workbooks.Count = 0 Then .Workbooks.Add
'Record current calculation state
xlCalcState = Application.Calculation
'Turn off screen updates and set calculation to manual
.ScreenUpdating = False
.DisplayAlerts = False
.Calculation = xlCalculationManual
End With
End Sub
Then when running in your macro:
On Error GoTo ErrHandler
'Do whatever your macro would normally do
Exit Sub
ErrHandler:
Call Environ_RestoreSettings
End Sub