API reference · Others

DisableMacroMode

Enables Excel events, screen updates and alerts, and selects automatic calculation.

SubOthers→No return value (Sub)Source L18

Signature#

VBA
Sub DisableMacroMode()

Parameters#

This procedure takes no parameters.

Returns#

Sub. No return value; overwrites four Application-wide Excel settings.

Example#

SEE THE TRANSFORMATIONChange Excel application settings
Before
Illustrative initial settingsValues / state

No array dimensions

ItemValue
ScreenUpdatingFalse
EnableEventsFalse
DisplayAlertsFalse
Calculation“Manual”
After
Immediately after the callValues / state

No array dimensions

ItemValue
ScreenUpdatingTrue
EnableEventsTrue
DisplayAlertsTrue
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.

VBA
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 Sub

Behavior and edge cases#

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
VBA
Sub DisableMacroMode()
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
    Application.Calculation = xlCalculationAutomatic
End Sub