Spoiler
This code is actually BAD for performances! So don't use it! ;)
For a while now, I've been using this wrapper to avoid retyping most of it :
Public Sub PerfWrap(SubNameToRun As String, _
Optional ByVal DispStatusBar As Boolean = False, _
Optional ArgumentsToPass As String = vbNullString)
Dim aWB As Workbook, _
ActiveSH As Worksheet, _
ScreenUpdateState As Boolean, _
StatusBarState As Boolean, _
CalcState As XlCalculation, _
EventsState As Boolean, _
DisplayPageBreakState As Boolean
Set aWB = ActiveWorkbook
Set ActiveSH = aWB.ActiveSheet
DoEvents
With Application
ScreenUpdateState = .ScreenUpdating
StatusBarState = .DisplayStatusBar
CalcState = .Calculation
EventsState = .EnableEvents
DoEvents
.ScreenUpdating = False
.DisplayStatusBar = DispStatusBar
.Calculation = xlCalculationManual
.EnableEvents = False
End With
DisplayPageBreakState = ActiveSH.DisplayPageBreaks
ActiveSH.DisplayPageBreaks = False
If ArgumentsToPass <> vbNullString Then
Application.Run SubNameToRun, ArgumentsToPass
Else
Application.Run SubNameToRun
End If
DoEvents
ActiveSH.Activate
ActiveSH.DisplayPageBreaks = DisplayPageBreakState
With Application
.ScreenUpdating = ScreenUpdateState
.DisplayStatusBar = StatusBarState
.StatusBar = vbNullString
.Calculation = CalcState
.EnableEvents = EventsState
End With
End Sub
I use it like this :
Public Sub Launcher_CopyAndUpdate()
Call PerfWrap("CopyAndUpdate_Templates", True)
End Sub
Or to pass arguments to the runned procedure :
Public Sub Launcher_Update()
Call PerfWrap("Update_Templates", True, "Arg1, Arg2")
End Sub
I was wondering if :
- it can be improved regarding performances
- converted as a function to return the value sent by the runned function
Anyhow, any input or opinion is very welcome! :)