This previous iteration of this question can be found hereA utility class to handle the state of the Application object.Storing the application's initial state (ScreenUpdating, EnableEvents, Calculation)  Disabling those settings for performance improvements  Restoring the original state  Operations that may need to temporarily modify Application Settings (Currently, writing to the StatusBar)Also comes with a module of Unit Tests (courtesy of Rubberduck's Unit Testing framework).How can I make it even better?I'm considering changing the name to ExcelApplicationState to make it clearer that it's a state-persistence object. Thoughts?Example UsageSub Example()    With New ExcelApplicationSettings '/ Store happens here        .Disable        '/ Code        '/ Code        .WriteToStatusBar Some Status Update        '/ Code        '/ Code        '/ Code        .WriteToStatusBar Operation Complete    End With '/ Restore happens hereEnd SubModule ExcelApplicationSettings'@Folder Application_SettingsOption Explicit'/ Object to store, reset and restore application settings for an Excel Application Instance'/ Default Behaviour:'/ When this class is created, immmediately set and store the application object that contains this workbook'/ When this class is terminated, immediately restore the original settingsPrivate Type appSettings    TargetApplication As Excel.Application    ScreenUpdating As Boolean    EnableEvents As Boolean    Calculation As XlCalculationEnd TypePrivate this As appSettingsPublic Property Set TargetApplication(ByVal app As Excel.Application)    Set this.TargetApplication = app    StoreEnd PropertyPublic Property Get TargetApplication() As Excel.Application    Set TargetApplication = this.TargetApplicationEnd PropertyPrivate Sub Class_Initialize()    Set TargetApplication = ThisWorkbook.ApplicationEnd SubPrivate Sub Class_Terminate()    RestoreEnd SubPublic Sub WriteToStatusBar(ByVal displayMessage As String)    With New ExcelApplicationSettings        this.TargetApplication.ScreenUpdating = True        this.TargetApplication.StatusBar = displayMessage    End WithEnd SubPrivate Sub Store()    '/ Stores the target application's settings    With this.TargetApplication        this.ScreenUpdating = .ScreenUpdating        this.EnableEvents = .EnableEvents        this.Calculation = .Calculation    End WithEnd SubPublic Sub Restore()    '/ Sets the target's application settings back to their last stored values    With this.TargetApplication        .ScreenUpdating = this.ScreenUpdating        .EnableEvents = this.EnableEvents        .Calculation = this.Calculation    End WithEnd SubPublic Sub Disable()    '/ Sets the target's application settings to off    With this.TargetApplication        .ScreenUpdating = False        .EnableEvents = False        .Calculation = xlCalculationManual    End WithEnd SubPublic Sub Reset()    '/ Restore application settings to defaults    With this.TargetApplication        .ScreenUpdating = True        .EnableEvents = True        .Calculation = xlCalculationAutomatic    End WithEnd SubModule ExcelApplicationSettings_Tests'@Folder Application_SettingsOption ExplicitOption Private Module'@TestModulePrivate Assert As ObjectPrivate OriginalSettings As ExcelApplicationSettings'@ModuleInitializePublic Sub ModuleInitialize()    'this method runs once per module.    Set Assert = CreateObject(Rubberduck.AssertClass)    Set OriginalSettings = New ExcelApplicationSettingsEnd Sub'@ModuleCleanupPublic Sub ModuleCleanup()    'this method runs once per module.    OriginalSettings.Restore    Set OriginalSettings = NothingEnd Sub'@TestInitializePublic Sub TestInitialize()    'this method runs before every test in the module.End Sub'@TestCleanupPublic Sub TestCleanup()    'this method runs after every test in the module.End Sub'@TestMethodPublic Sub GivenFalseResetScreenUpdating()    On Error GoTo TestFail    Application.ScreenUpdating = False    With New ExcelApplicationSettings        .Reset        Assert.Istrue Application.ScreenUpdating = True    End WithTestExit:    Exit SubTestFail:    Assert.Fail Test raised an error: # & Err.Number &  -  & Err.DescriptionEnd Sub'@TestMethodPublic Sub GivenFalseResetEnableEvents()    On Error GoTo TestFail    Application.EnableEvents = False    With New ExcelApplicationSettings        .Reset        Assert.Istrue Application.EnableEvents = True    End WithTestExit:    Exit SubTestFail:    Assert.Fail Test raised an error: # & Err.Number &  -  & Err.DescriptionEnd Sub'@TestMethodPublic Sub GivenManualResetCalculation()    On Error GoTo TestFail    Application.Calculation = xlCalculationManual    With New ExcelApplicationSettings        .Reset        Assert.Istrue Application.Calculation = xlCalculationAutomatic    End WithTestExit:    Exit SubTestFail:    Assert.Fail Test raised an error: # & Err.Number &  -  & Err.DescriptionEnd Sub'@TestMethodPublic Sub GivenTrueDisableScreenUpdating()    On Error GoTo TestFail    Application.ScreenUpdating = True    With New ExcelApplicationSettings        .Disable        Assert.Istrue Application.ScreenUpdating = False    End WithTestExit:    Exit SubTestFail:    Assert.Fail Test raised an error: # & Err.Number &  -  & Err.DescriptionEnd Sub'@TestMethodPublic Sub GivenTrueDisableEnableEvents()    On Error GoTo TestFail    Application.EnableEvents = True    With New ExcelApplicationSettings        .Disable        Assert.Istrue Application.EnableEvents = False    End WithTestExit:    Exit SubTestFail:    Assert.Fail Test raised an error: # & Err.Number &  -  & Err.DescriptionEnd Sub'@TestMethodPublic Sub GivenAutomaticDisableCalculation()    On Error GoTo TestFail    Application.Calculation = xlCalculationAutomatic    With New ExcelApplicationSettings        .Disable        Assert.Istrue Application.Calculation = xlCalculationManual    End WithTestExit:    Exit SubTestFail:    Assert.Fail Test raised an error: # & Err.Number &  -  & Err.DescriptionEnd Sub'@TestMethodPublic Sub GivenScreenUpdatingRestoreOnTerminate()    On Error GoTo TestFail    Application.ScreenUpdating = True    With New ExcelApplicationSettings '/ Store happens here        Application.ScreenUpdating = False    End With '/ Restore happens here    Assert.Istrue Application.ScreenUpdating = TrueTestExit:    Exit SubTestFail:    Assert.Fail Test raised an error: # & Err.Number &  -  & Err.DescriptionEnd Sub'@TestMethodPublic Sub GivenEnableEventsRestoreOnTerminate()    On Error GoTo TestFail    Application.EnableEvents = True    With New ExcelApplicationSettings '/ Store happens here        Application.EnableEvents = False    End With '/ Restore happens here    Assert.Istrue Application.EnableEvents = TrueTestExit:    Exit SubTestFail:    Assert.Fail Test raised an error: # & Err.Number &  -  & Err.DescriptionEnd Sub'@TestMethodPublic Sub GivenCalculationRestoreOnTerminate()    On Error GoTo TestFail    Application.Calculation = xlCalculationAutomatic    With New ExcelApplicationSettings '/ Store happens here        Application.Calculation = xlCalculationManual    End With '/ Restore happens here    Assert.Istrue Application.Calculation = xlCalculationAutomaticTestExit:    Exit SubTestFail:    Assert.Fail Test raised an error: # & Err.Number &  -  & Err.DescriptionEnd Sub'@TestMethodPublic Sub GivenDefaultObjectTargetHostApplication()    '/ Test that the object's default behaviour is to store ThisWorkbook.Application upon creation    On Error GoTo TestFail    With New ExcelApplicationSettings        Assert.Istrue ObjPtr(ThisWorkbook.Application) = ObjPtr(.TargetApplication)    End WithTestExit:    Exit SubTestFail:    Assert.Fail Test raised an error: # & Err.Number &  -  & Err.DescriptionEnd Sub'@TestMethodPublic Sub WriteToStatusBar()    '/ Test that the object's default behaviour is to store ThisWorkbook.Application upon creation    On Error GoTo TestFail    Dim originalMessage As String    originalMessage = Application.StatusBar    Dim testMessage As String    testMessage = Test Message    With New ExcelApplicationSettings        .WriteToStatusBar testMessage        Assert.Istrue Application.StatusBar = testMessage    End WithTestExit:    Application.StatusBar = originalMessage    Exit SubTestFail:    Assert.Fail Test raised an error: # & Err.Number &  -  & Err.Description    Application.StatusBar = originalMessageEnd Sub'@TestMethodPublic Sub PreserveFalseScreenUpdatingAfterWriteToStatusBar()    '/ Check that writing to status bar doesn't change the state of Application.ScreenUpdating    On Error GoTo TestFail    Dim originalMessage As String    originalMessage = Application.StatusBar    Dim testMessage As String    testMessage = Test Message    With New ExcelApplicationSettings        Application.ScreenUpdating = False        .WriteToStatusBar testMessage        Assert.Istrue Application.ScreenUpdating = False    End WithTestExit:    Application.StatusBar = originalMessage    Exit SubTestFail:    Assert.Fail Test raised an error: # & Err.Number &  -  & Err.Description    Application.StatusBar = originalMessageEnd Sub'@TestMethodPublic Sub PreserveTrueScreenUpdatingAfterWriteToStatusBar()    '/ Check that writing to status bar doesn't change the state of Application.ScreenUpdating    On Error GoTo TestFail    Dim originalMessage As String    originalMessage = Application.StatusBar    Dim testMessage As String    testMessage = Test Message    With New ExcelApplicationSettings        Application.ScreenUpdating = True        .WriteToStatusBar testMessage        Assert.Istrue Application.ScreenUpdating = True    End WithTestExit:    Application.StatusBar = originalMessage    Exit SubTestFail:    Assert.Fail Test raised an error: # & Err.Number &  -  & Err.Description    Application.StatusBar = originalMessageEnd Sub
ApplicationSettings Class for disabling/restoring Application State
unit testing;vba;excel;rubberduck;state