PDA

View Full Version : [SOLVED:] More Info on Program "XLAppRest"



Cyberdude
09-11-2005, 04:07 PM
A couple of you fine folks have referred to the program that is named either "XLAppRest" or "XLAppReset" that is presumably associated with resetting all the statements like "Application.Calculation" to their default values. Sorry to say I haven't heard of it before now. Where can I find more info on it? http://vbaexpress.com/forum/images/smilies/eek.gif

Ken Puls
09-11-2005, 05:51 PM
Hey Sid,

It's actually a custom built subroutine used to restore the default states of your environment before you ran your code. Every coder would use most of the same items, but some may omit a few as they don't use certain pieces...

I call my own something different, but you'll get the idea here. In mine, I call Environ_SpeedBooster at the beginning of each major subroutine, and then Environ_RestoreSettings at the end, or after an error forces an exit.

These have been cut directly from one of my projects...


Public xlCalcState As Long

Sub Environ_SpeedBooster()
'Macro created 06/11/2005 22:29 by Ken Puls
'Macro Purpose: To set application properties to maximize speed
xlCalcState = Application.Calculation
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
End Sub

Sub Environ_RestoreSettings()
'Macro created 06/11/2005 22:33 by Ken Puls
'Macro Purpose: To restore application properties to user settings
With Application
.ScreenUpdating = True
.Calculation = xlCalcState
.EnableEvents = True
.DisplayAlerts = True
.StatusBar = False
End With
xlCalcState = 0
End Sub


HTH,

Cyberdude
09-11-2005, 08:48 PM
Hey, Ken, that's exactly what I wanted to know. I guess I do the same thing functionally (I write each reset statement), I just never thought to gather it together into one utility macro and call it from my procedure. Duh! I thought that maybe there was an "official" utility that sits in the dark and misty recesses of Excel somewhere. I can write one of those ... and I will!!
Thanx for the reply and code. http://vbaexpress.com/forum/images/smilies/friendship.gif

Ken Puls
09-11-2005, 09:22 PM
Hey Sid!

No problems at all. :) The nice thing about this format is that if you do step through your code and stop the execution before your reset runs, you just have to run that procedure and you're good. Add it to a shortcut key, and you can do it very quickly from the Excel interface if necessary as well.

For my own purposes, when I'm building an addin, I don't always put in all those pieces in the restore part. For example, if I don't ever disable events or alerts, I'll skip


.EnableEvents = True
.DisplayAlerts = True