API reference · Others
DisableMacroMode
Enables Excel events, screen updates and alerts, and selects automatic calculation.
Signature#
Sub DisableMacroMode()Parameters#
This procedure takes no parameters.
Returns#
Sub. No return value; overwrites four Application-wide Excel settings.
Example#
Before
Illustrative initial settingsValues / state
No array dimensions
| Item | Value |
|---|---|
| ScreenUpdating | False |
| EnableEvents | False |
| DisplayAlerts | False |
| Calculation | “Manual” |
After
Immediately after the callValues / state
No array dimensions
| Item | Value |
|---|---|
| ScreenUpdating | True |
| EnableEvents | True |
| DisplayAlerts | True |
| Calculation | “Automatic” |
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 ExampleOthersDisableMacroMode()
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.DisableMacroMode
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.EnableEvents=True, Application.ScreenUpdating=True, Application.DisplayAlerts=True, then Application.Calculation=xlCalculationAutomatic, in that order.
- Always writes those fixed values, even if the user originally had manual calculation, disabled events or suppressed alerts. It does not consult any saved state from SetMacroMode.
- The changes affect the Excel Application, not just ThisWorkbook. Enabling automatic calculation can cause Excel to recalculate.
- There is no internal error handling or rollback; earlier settings can remain changed when a later assignment fails. The example captures and restores the original settings in its cleanup path.
Performance#
Four property assignments: O(1) explicit VBA work. Enabling automatic calculation can incur additional workbook recalculation time determined by Excel and the open workbooks.
View implementation
Sub DisableMacroMode()
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.Calculation = xlCalculationAutomatic
End Sub