API reference · Others
SetMacroMode
Disables Excel screen updates, events and alerts, and selects manual calculation.
Signature#
Sub SetMacroMode()Parameters#
This procedure takes no parameters.
Returns#
Sub. No return value; changes four Application-wide Excel settings.
Example#
Before
Illustrative initial settingsValues / state
No array dimensions
| Item | Value |
|---|---|
| ScreenUpdating | True |
| EnableEvents | True |
| DisplayAlerts | True |
| Calculation | “Automatic” |
After
Immediately after the callValues / state
No array dimensions
| Item | Value |
|---|---|
| ScreenUpdating | False |
| EnableEvents | False |
| DisplayAlerts | False |
| Calculation | “Manual” |
These are application settings, so array shape does not apply. The initial state is illustrative; the example captures the actual settings and restores them afterward.
Shaded headers are array indices, not data. Quoted cells are text. Values shown are derived from the source, not an Excel execution.
Option Explicit
Public Sub ExampleOthersSetMacroMode()
Dim utility As New Others
Dim oldUpdating As Boolean, oldEvents As Boolean
Dim oldAlerts As Boolean, oldCalculation As XlCalculation
Dim savedNumber As Long, savedDescription As String
oldUpdating = Application.ScreenUpdating
oldEvents = Application.EnableEvents
oldAlerts = Application.DisplayAlerts
oldCalculation = Application.Calculation
On Error GoTo Failed
utility.SetMacroMode
Debug.Print Application.Calculation
RestoreSettings:
On Error Resume Next
Application.Calculation = oldCalculation
Application.DisplayAlerts = oldAlerts
Application.EnableEvents = oldEvents
Application.ScreenUpdating = oldUpdating
On Error GoTo 0
If savedNumber <> 0 Then Err.Raise savedNumber, , savedDescription
Exit Sub
Failed:
savedNumber = Err.Number
savedDescription = Err.Description
Resume RestoreSettings
End SubBehavior and edge cases#
- Sets Application.ScreenUpdating=False, Application.EnableEvents=False, Application.DisplayAlerts=False, then Application.Calculation=xlCalculationManual, in that order.
- These are Excel Application settings affecting the running Excel instance. The routine does not retain prior settings or track nesting.
- There is no internal error handling or automatic rollback. An error while assigning a later property may leave earlier properties changed.
- DisableMacroMode sets fixed enabled/automatic values; it does not restore a previous state. Capture the original properties and restore them in a cleanup path when the caller must preserve user settings.
- The example briefly invokes this API and restores the previously captured settings. It has not been executed against Excel during documentation generation.
Performance#
Four property assignments: O(1) explicit VBA work. Changes to Excel calculation and application behavior can have host-dependent costs.
View implementation
Sub SetMacroMode()
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.DisplayAlerts = False
Application.Calculation = xlCalculationManual
End Sub