Maybe you could use somthing like this, Jeff. It maintains a stack of states so subs can push their desired state and then pop to return to the state when they were called. You can skip arguments that you don't care about.
Minimally tested.
Option Explicit
Public Enum AppMode
Pop
Reset
Push
End Enum
Sub demo()
' set calculation to manual and screen updating to false
AppOnOff Push, iCalc:=xlCalculationManual, tsScreen:=vbFalse
' do stuff
AppOnOff Pop
End Sub
Sub AppOnOff(iMode As AppMode, _
Optional iCalc As XlCalculation = 0, _
Optional tsAlerts As VbTriState = vbUseDefault, _
Optional tsEvents As VbTriState = vbUseDefault, _
Optional tsScreen As VbTriState = vbUseDefault)
' iMode Action
' -1 Pop to last state
' 0 Reset state, everything on
' 1 Push current state, set new states
Static col As Collection
Dim vSta As Variant
If col Is Nothing Then Set col = New Collection
With Application
Select Case iMode
Case Pop
If col.Count Then
vSta = col.Item(col.Count)
col.Remove col.Count
.Calculation = vSta(0)
.DisplayAlerts = vSta(1)
.EnableEvents = vSta(2)
.ScreenUpdating = vSta(3)
End If
Case Reset
Set col = New Collection
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
.EnableEvents = True
.ScreenUpdating = True
Case Push
col.Add VBA.Array(.Calculation, .DisplayAlerts, .EnableEvents, .ScreenUpdating)
If iCalc <> 0 Then .Calculation = iCalc
If tsAlerts <> vbUseDefault Then .DisplayAlerts = tsAlerts
If tsEvents <> vbUseDefault Then .EnableEvents = tsEvents
If tsScreen <> vbUseDefault Then .ScreenUpdating = tsScreen
End Select
End With
End Sub
Bookmarks