tags:

views:

92

answers:

4

what is the point of doing these:

Application.ScreenUpdating = False
Application.DisplayAlerts = False

does it really save that much time?

+1  A: 

Absolutely. I had a long-running macro several years ago that took almost a minute to run. I set ScreenUpdating to false and it finished in less than 5 seconds.

Just make sure you reset ScreenUpdating to true when you're finished running the macro.

Michael Todd
Also dont forget to set ScreenUpdating back on as the first step in any error handeling code you have
Kevin Ross
+1  A: 

It depends on how much you are actually updating on the screen as part of your code, (i.e. number of cells updated), and how many sheets are there, how many sheets/cells refer to sheet your code is updating and how many formulas are present in the whole workbook.

Each time you change some thing in the sheet, Excel re-calculates all formulas. So if your code is not updating too many sheets/cells but your workbook has many formulas then turning off the screen update might not help you at all.

One more thing to consider for perfomance is Calculation property, set this to xlCalculationManual to turnn off the auto recals and turn it back to xlCalculationAutomatic at the end.

Application.Calculation = xlCalculationManual

One more thing to conside is Events, if one or more of those sheets have Worksheet_Chnage or Worksheet_Calculate event handlers each change that your code is doing will trigger them and your code need to wait till they return. So turn it off during your code.

Application.EnableEvents = False

In most of my code, I susally use this

On Error GoTo lblError
Dim bEvents As Boolean, iCalc As Integer, bScrnUpd As Boolean
bEvents = Application.EnableEvents
iCalc = Application.Calculation
bScrnUpd = Application.ScreenUpdating
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False

'-----------------------My code

Application.EnableEvents = bEvents
Application.Calculation = iCalc
Application.ScreenUpdating = bScrnUpd
Exit Sub

'reset them even if you are exiting due to error
lblError:
Application.EnableEvents = bEvents
Application.Calculation = iCalc
Application.ScreenUpdating = bScrnUpd
Debug.print Err.Description
Adarsha
+1  A: 

The improvement of screenUpdating depends largely on how your macro is written. It will be specially usefull with those horrible macros made by the recorder, full of unnecessary "select" and "activate".

iDevlop
+1  A: 

I wouldn't use those for 'speed' but for 'function'

When you don't want the user to see the screen updating:

Application.ScreenUpdating = False

When you don't want the user to see every superfluous message from the app:

Application.DisplayAlerts = False 

Especially the latter because no one wants to be bludgeoned to death with messages asking if you 'really' want to update, append or delete records. I prefer to shield the user from such stuff.

Chris