Monday, September 26, 2016

Excel VBA exception handling & performance boost

Sub MainMacro()
    Dim calculationMode As Integer
    calculationMode = Application.Calculation
   
    On Error GoTo Err_Finally
    Application.Calculation = xlCalculationManual
    Application.ScreenUpdating = False
   
    Do Something......
   
Exit_Sub:
    Application.CutCopyMode = False
   
    Application.ScreenUpdating = True
    Application.Calculation = calculationMode
    Exit Sub
   
Err_Finally:
    MsgBox Err.Description
    Resume Exit_Sub
End Sub

No comments: