I am a supporter of St. Joseph's hospice. If you find this site useful or if it helped you, consider a small donation to St. Joseph's, please.
"Any sufficiently advanced technology is indistinguishable from magic." [Arthur C. Clarke]
My friend and colleague Jon T. created the smallest reasonable class module I have seen so far: SystemState provides an easy way to save and to restore system state variables like Calculation, ScreenUpdating and others.
Normally you write at the beginning of a VBA macro
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
and at the end of a macro
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
With the class module SystemState you just write at the start
Dim state As SystemState
Set state = New SystemState
Call state.Save(True) 'Just to set favorite parameters - New SystemState has already saved previous values
and at the end
Set state = Nothing 'Not even necessary - will be done automatically
If you change the code in sub Class_Initialize below to Call Save(True) then you just need to put at the beginning of each of your subs
Dim state As SystemState
Set state = New SystemState
and the system state variables will be stored, your favorite default values get initialized and at the end of the sub the stored values get restored.
[But remember: You cannot abbreviate this to "Dim state as New SystemState"!]
You can control a whole bunch of system state variables:
|
Variable |
States |
Comment (speed up with ...) |
|
Calculation |
xlCalculationAutomatic |
Decides whether a recalc is done after each change to any cell. Set to xlCalculationManual |
|
Cursor |
xlDefault |
This is just user info. Set to xlWait (hourglass) if you like - but only after having tested your code thoroughly - it is quite annoying to start debugging with an hourglass cursor |
|
DisplayAlerts |
True |
If your macro knows what to do it is quite annoying if the system asks you whether you want to overwrite an existing file, for example. Set to False to switch off |
|
EnableEvents |
True |
Set to False to prevent event procedures from being run |
|
Interactive |
True |
If set to False all keyboard input will be blocked. Dangerous |
|
ScreenUpdating |
True |
Set to False to prevent screen from updating during run |
|
StatusBar |
False |
Text will show up at status bar (bottom line). Cleared if set to False |

If you are interested in downloading a 26 KB Excel 2007 sample file go to my Download page, please.



[Sulprobil] [Get it done] [Organisation] [IT] [Controlling] [Human Resources] [Family] [Contact] [Download] [Disclaimer]