Application-level Properties
On this page we'll go through and dissect a number of Application-level properties which can be set programmatically. Most importantly, these are functions which can be separated out and encapsulated into their own functions to keep them out of event handlers (where they usually reside).
I'll present two sets of procedures: one to return the current value of an Application property, and one to set the value. Most of the 'set'ting procedures have a default value, which you can change if you like. I've also included comments in some of the functions to explain what they do.
Note that this is not a full list of Application properties. Check the Object Browser (F2 in the VB IDE) for the complete listing.
Application.EnableCancelKey
To return the cancel key, we use a Variant type, so you can return either the Long variable that the EnableCancelKey property represents, or a String representation of the XlEnableCancelKey constant.
From Excel Help:
Controls how Microsoft Excel handles CTRL+BREAK (or ESC or COMMAND+PERIOD) user interruptions to the running procedure. Read/write XlEnableCancelKey.
Dim cancelKey As String
GetCancelKey = Application.EnableCancelKey
' uncomment the following lines if you want a string instead of the number
' Select Case GetCancelKey
' Case 0
' cancelKey = "xlDisabled"
' Case 1
' cancelKey = "xlInterrupt"
' Case 2
' cancelKey = "xlErrorHandler"
' End Select
' GetCancelKey = cancelKey
End Function
Application.EnableCancelKey = cancelKey
End Function
Application.FeatureInstall
From Excel Help:
Returns or sets a value (constant) that specifies how Microsoft Excel handles calls to methods and properties that require features that aren’t yet installed. Can be one of the MsoFeatureInstall constants listed in the following table. Read/write MsoFeatureInstall.
Dim installNewFeature As String
GetInstallNewFeature = Application.FeatureInstall
' uncomment the following lines if you want a string instead of the number
' Select Case GetInstallNewFeature
' Case 0
' installNewFeature = "msoFeatureInstallNone"
' Case 1
' installNewFeature = "msoFeatureInstallOnDemand"
' Case 2
' installNewFeature = "msoFeatureInstallOnDemandWithUI"
' End Select
' GetInstallNewFeature = installNewFeature
End Function
Application.FeatureInstall = whatToDo
End Function
Application.ShowChartTipNames
From Excel Help:
True if charts show chart tip names. The default value is True. Read/write Boolean.
ChartTipNamesShown = Application.ShowChartTipNames
End Function
Application.ShowChartTipNames = chartNames
End Function
Application.ShowChartTipValues
From Excel Help:
True if charts show chart tip values. The default value is True. Read/write Boolean.
ChartTipsShown = Application.ShowChartTipValues
End Function
Application.ShowChartTipValues = chartTips
End Function
Application.ShowToolTips
From Excel Help:
True if ToolTips are turned on. Read/write Boolean.
ToolTipsShown = Application.ShowToolTips
End Function
Application.ShowToolTips = showTT
End Function
Application.ShowWindowsInTaskbar
From Excel Help:
True if there’s a separate Windows taskbar button for each open workbook. The default value is True. Read/write Boolean.
GetShowWindows = Application.ShowWindowsInTaskbar
End Function
Application.ShowWindowsInTaskbar = showWnd
End Function
Application.ScreenUpdating
Toggle screen updating with these functions.
From Excel Help:
True if screen updating is turned on. Read/write Boolean.
IsScreenUpdating = Application.ScreenUpdating
End Function
Application.ScreenUpdating = showUpdates
End Function
Application.MaxIterations
Set the number of iterations for a circular reference in your spreadsheet model.
From Excel Help:
Returns or sets the maximum number of iterations that
Microsoft Excel can use to resolve a circular reference. Read/write Long.
GetNumberOfIterations = Application.MaxIterations
End Function
Application.MaxIterations = num
End Function
Application.EnableEvents
Check if events are enabled, and if so, disable them.
From Excel Help:
True if events are enabled for the specified object. Read/write Boolean.
IsEventsDisabled = Not Application.EnableEvents
End Function
' toggle events, assume true (events disabled)
Application.EnableEvents = Not events
End Function
Edit in Cell
See Leveraging the Edit Directly in Cell Option for a good explanation of how this option works.
GetEditInCell = Application.EditDirectlyInCell
End Function
' toggle in-cell editing, assume false
Application.EditDirectlyInCell = ed
End Function
Showing the Status Bar
IsStatusBarDisplayed = Application.DisplayStatusBar
End Function
' toggle status bar, assumes false
Application.DisplayStatusBar = showStatusBar
End Function
The MRU list
From Excel Help:
True if the list of recently used files is displayed on the File menu. Read/write Boolean.
IsRecentFilesListShown = Application.DisplayRecentFiles
End Function
' toggle Display Recent Files property, assume true
Application.DisplayRecentFiles = showFiles
End Function
Toggle the Formula Bar
From Excel Help:
True if the formula bar is displayed. Read/write Boolean.
IsFormulaBarDisplayed = Application.DisplayFormulaBar
End Function
' toggle formula bar, assumes false
Application.DisplayFormulaBar = showformBar
End Function
Showing or hiding comments
From Excel Help:
Returns or sets the way cells display comments and indicators. Can be one of the following xlCommentDisplayMode constants: xlNoIndicator, xlCommentIndicatorOnly, or xlCommentAndIndicator. Read/write Long.
Dim commentIndicator As String
GetCommentIndicator = Application.DisplayCommentIndicator
' uncomment the following lines if you want a string instead of the number
' Select Case GetCommentIndicator
' Case 1
' commentIndicator = "xlCommentAndIndicator"
' Case -1
' commentIndicator = "xlCommentIndicatorOnly"
' Case 0
' commentIndicator = "xlNoIndicator"
' End Select
' GetCommentIndicator = commentIndicator
End Function
' toggles comment indicators on worksheet
Application.DisplayCommentIndicator = commentType
End Function
Don't allow the clipboard window
From Excel Help:
Returns True if the Microsoft Office Clipboard can be displayed. Read/write Boolean.
GetDisplayClipboardWindow = Application.DisplayClipboardWindow
End Function
' toggle display of the clipboard window, assumes false
Application.DisplayClipboardWindow = showWindow
End Function
Displaying Alerts
One of the most important (along with ScreenUpdating and EnableEvents).
From Excel Help:
True if Microsoft Excel displays certain alerts and messages while a macro is running. Read/write Boolean.
GetDisplayAlerts = Application.displayAlerts
End Function
' sets the Display Alerts property, assumes false
Application.displayAlerts = showAlerts
End Function
Interrupting Calculations
From Excel Help:
Sets or returns an XlCalculationInterruptKey constant that specifies the key that can interrupt Microsoft Excel when performing calculations. Read/write.
Dim calcInterruptKey As String
GetCalcInterruptKey = Application.CalculationInterruptKey
' uncomment the following lines if you want a string instead of the number
' Select Case GetCalcInterruptKey
' Case 0
' calcInterruptKey = "xlNoKey"
' Case 1
' calcInterruptKey = "xlEscKey"
' Case 2
' calcInterruptKey = "xlAnyKey"
' End Select
' GetCalcInterruptKey = calcInterruptKey
End Function
' sets the calculation interruption key
Application.CalculationInterruptKey = key
End Function
Toggle Calculation mode
From Excel Help:
Returns or sets the calculation mode. Read/write XlCalculation.
Dim calcMode As String
GetCalcMode = Application.Calculation
' uncomment the following lines if you want a string instead of the number
' Select Case GetCalcMode
' Case -4105
' calcMode = "Automatic"
' Case -4135
' calcMode = "Manual"
' Case 2
' calcMode = "Semiautomatic"
' End Select
' GetCalcMode = calcMode
End Function
' change calculation mode
' assumes automatic calculation
' see http://tinyurl.com/yjefjf5 for reasons
Application.Calculation = calc
End Function
Toggle Calculation Before Save
From Excel Help:
True if workbooks are calculated before they're saved to disk (if the Calculation property is set to xlManual). This property is preserved even if you change the Calculation property. Read/write Boolean.
GetCalcBeforeSave = Application.CalculateBeforeSave
End Function
' toggle CalculateBeforeSave
Application.CalculateBeforeSave = calc
End Function
Updating Links
One of the most annoying properties. If your workbook has links, you can stop them from asking if you want the links updated.
From Excel Help:
True if Microsoft Excel asks the user to update links when opening files with links. False if links are automatically updated with no dialog box. Read/write Boolean.
GetUpdateLinks = Application.AskToUpdateLinks
End Function
' toggle AskToUpdateLinks property, defaults to True
Application.AskToUpdateLinks = toUpdate
End Function