Injecting pre-written Functions into Workbook Projects via VBA
During a recent interview I was asked to talk through a VBA Function that sets many of the application settings (Screen Updating, Enable Events, Display Alerts, etc) and a Function that returns them to their original values and it reminded me of something i started putting together a few years ago that injected some pre-defined functions within a Workbooks VBA Project via Userform.
Credit where it's due, the FindLast Function was Steve Southwick's (https://www.dhirubhai.net/in/steve-southwick-7b5187a0/). Remember putting these together Steve?
For anyone wanting to have a play feel free to download the add-in. I have left the Project unlocked should you want to mimic the functionality or Functions. Please note the Add-In only works if you check 'Trust Access to VBA Project' in Excel's Options. The add-in should show you how to do this when you open the tool via the Add-Ins menu.
https://drive.google.com/open?id=0B8-3mVn08WeSa1dtNEdnQVRxcFU
Should you just want the function mentioned above here you go...
Option Explicit
Public blnSavedScreenUpdating As Boolean
Public blnSavedEnableEvents As Boolean
Public blnSavedDisplayAlerts As Boolean
Public lngSavedCalculation As Long
Public blnSavedCancel As Boolean
Public Enum CalcTypes
Manual = 0
Automatic = 1
AutomaticExceptTables = 2
End Enum
Function AppSettings(blnScreenUpdating As Boolean, _
blnEnableEvents As Boolean, _
blnDisplayAlerts As Boolean, _
lngCalculation As CalcTypes, _
blnCancel As Boolean, _
Optional blnSaveSettings As Boolean)
'From: NuFunc Excel Add-In
'Author: Michael Blackman
'Date Created: 27th July 2011
'Supported Operating Systems: Windows XP, Vista, Win7
'Compatible Versions: Excel 2000, 2003, 2007, 2010
With Application
If blnSaveSettings = True Then
blnSavedScreenUpdating = .ScreenUpdating
blnSavedEnableEvents = .EnableEvents
blnSavedDisplayAlerts = .DisplayAlerts
lngSavedCalculation = .Calculation
blnSavedCancel = .EnableCancelKey
End If
.ScreenUpdating = blnScreenUpdating
.EnableEvents = blnEnableEvents
.DisplayAlerts = blnDisplayAlerts
.Calculation = lngCalculation
.EnableCancelKey = blnCancel
End With
End Function
Function RestoreAppSettings()
'From: NuFunc Excel Add-In
'Author: Michael Blackman
'Date Created: 27th July 2011
'Supported Operating Systems: Windows XP, Vista, Win7
'Compatible Versions: Excel 2000, 2003, 2007, 2010
With Application
.ScreenUpdating = blnSavedScreenUpdating
.EnableEvents = blnSavedEnableEvents
.DisplayAlerts = blnSavedDisplayAlerts
.Calculation = lngSavedCalculation
.EnableCancelKey = blnSavedCancel
End With
End Function
Healthcare & Life Sciences Innovator | Director, Data & IT Ops with Full-Cycle Expertise (Dev, PM, Ops) | Strategic Leader Driving Value-Based Clinical Outcomes & Project Revitalization
8 年Hey Mike, I do remember putting these together! In fact, is still use and have added quite a few that I found useful along the way. Thanks for posting this and remembering me, it was fun putting these together!
Data Analyst COG P&C at Chubb
8 年:-)