Dumitru Daniel
Dumitru Daniel

Reputation: 549

VBA Performance, what order should use to disable / enable screen updating

I have a macro in place that toggles the following:

 Application.ScreenUpdating = False
 Application.EnableEvents = False
 Application.DisplayAlerts = False
 Application.Calculation = xlCalculationManual

I turn them all on/off at the same time, but I noticed that sometimes EnableEvents does not turn back on, and screenUpdating does not turn off.

Is there a specific order I should follow because they somehow affect each other when toggling them?

Upvotes: 1

Views: 9482

Answers (2)

ThunderFrame
ThunderFrame

Reputation: 9471

Rather than setting all of those back to True, which can cause problems for people that have explicitly set calculation to manual, you should record the current settings, before changing anything, and then restore the settings to their original values when you are done. See CodeReview for an example of a class that manages this for you.

The only interaction might come about with Calculation and EnableEvents, but only if there are events configured for worksheet/workbook calculate.

Upvotes: 1

Vityata
Vityata

Reputation: 43595

Is there a specific order I should follow because they somehow affect each other when toggling them?

No.


Concerning non-toggling off or on, probably somewhere in the code you are having On Error GoTo Somewhere and you are skipping the lines with the toggling? (Just guessing).

Upvotes: 1

Related Questions