Disable time wasters - danielep71/VBA-PERFORMANCE GitHub Wiki

[Home]] ](/danielep71/VBA-PERFORMANCE/wiki/[[Previous|The-Optimization-process) | Next


In MS Excel, some Application properties slow down the code execution, most of the time, without any benefit.

You can disable these effects at the beginning of your procedure and re-enable them at the end.

Sub DisableTimeWasters()
    'Turns off the time wasters
    With Application
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
        .EnableEvents = False
        .DisplayAlerts = False
        .Cursor = xlWait
        .EnableCancelKey = xlErrorHandler
    End With
**End Sub**

**Sub EnableTimeWasters()**
    'Turns on the time wasters
    With Application
        .Calculation = xlCalculationAutomatic
        .ScreenUpdating = True
        .EnableEvents = True
        .DisplayAlerts = True
        .Cursor = xlDefault
        .StatusBar = False
        .EnableCancelKey = xlInterrupt
    End With
**End Sub**

Using these settings can make a huge difference in speed.

**Sub MyMacro()**
    'Turns off the time wasters
        DisableTimeWasters
 
    'Your code here
        ....

    'Turns on the time wasters
        EnableTimeWasters
**End Sub**

The class module cPerformanceManager can handle these two procedures. In particular, before disabling time wasters, it saves the current settings.


[Home]] ](/danielep71/VBA-PERFORMANCE/wiki/[[Previous|The-Optimization-process) | Next