t0ny84
Board Regular
- Joined
- Jul 6, 2020
- Messages
- 205
- Office Version
- 365
- 2016
- 2013
- Platform
- Windows
- Mobile
- Web
Hi Again!
Just wondering if anyone knows if it is possible to add settings or flags to a function or sub so that it would action based on those flags.
To cut down on adding it to each macro and also to make something which can be imported across numerous workbooks I am creating a "Common Utilities Module" which I can import to the workbook and then call the relevant utility\command.
E.g. With this code user would type
and it would turn Calculations from Automatic to Manual.
Just wondering if anyone knows if it is possible to add settings or flags to a function or sub so that it would action based on those flags.
To cut down on adding it to each macro and also to make something which can be imported across numerous workbooks I am creating a "Common Utilities Module" which I can import to the workbook and then call the relevant utility\command.
E.g. With this code user would type
VBA Code:
Call SpeedUpOn (Xcalc)
VBA Code:
Public Function SpeedUpOn(Optional xCalc As Boolean, Optional xEvent = "Events", Optional xScreen = "Screen", Optional xStatus = "StatusBar", Optional xAlerts = "Alerts", Optional xPageBreaks = "PageBreaks")
' Arguments For SpeedUpOn
' Calc - Sets Calculation From Automatic to Manual
' Events - Turns Enable Events Off
' Screen - Turns Screen Updating Off
' StatusBar - Turns Display Status Bar Off
' Alerts - Turns Display Alerts Off
' PageBreaks - Turns Display Page Breaks Off
' To Use In Your Code
' Put Below At The Top Of Your Code
' Call SpeedUpOn("calc", "Event", "Screen", "statusbar")
' Put Below At The Bottom Of Your Code
' Call SpeedUpOff
With Application
If Not xCalc Then
.Calculation = xlCalculationAutomatic
Else
.Calculation = xlCalculationManual
End If
If Events = True Then
.EnableEvents = False
Else
.EnableEvents = True
End If
If Screen = True Then
.ScreenUpdating = False '
Else
.ScreenUpdating = True
End If
If Status = True Then
.DisplayStatusBar = False
Else
.DisplayStatusBar = True
End If
If Alerts = True Then
.DisplayAlerts = False
Else
.DisplayAlerts = True
End If
End With
If PageBreaks = True Then
ActiveSheet.DisplayPageBreaks = False
Else
ActiveSheet.DisplayPageBreaks = True
End If
End Function