Turning error checking off and back on again for the current file

Earthsea

New Member
Joined
Apr 16, 2012
Messages
2
Dear All,

Background: I am an experienced programmer but a novice with Excel macros and VBA so please bear with me.

Summary: I have a situation where I want to turn error checking off and back on again for specific Excel files but not for all files i.e. not for the entire 'Excel' application.

Details: in ThisWorkbook I have the following private subroutines:

Private Sub Workbook_Open()
MsgBox ("Error checking OFF in Workbook_Open()")
Application.ErrorCheckingOptions.NumberAsText = False
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
MsgBox ("Error checking ON in Workbook_BeforeClose()")
Application.ErrorCheckingOptions.NumberAsText = True
End Sub

They work fine. Here's the problem: these private subs are in an Excel file that we'll call A.xlsx. I make two new files - B and C - by copying A. If I open B the error checking is turned off correctly. If I then open C the error checking is once again turned off correctly. BUT if I then close C the error checking is turned back on again - and not just for C but also for file B. What I would like is for the error checking to remain off within B until it too is closed. If I were to open an unrelated file D I would want the error checking in that to be on as it should be by default.

Even though I am using the 'Application' object I had presumed that having the private subs in ThisWorkbook would limit their scope but I think that I'm starting to see that I may have misunderstood.

Is it possible to do what I am trying to do? Since the attribute ErrorCheckingOptions does not exist for the object ActiveWorksheet (which I tried on a hunch) I think that the answer may be 'No'...

Thank you.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Hi and Welcome to the Board,

As you've discovered, changing the Application object affects the User interface for all Workbooks in that instance of Excel.

If you want to control this separately for different Workbooks you might consider using the Workbook_Activate Event to trigger the toggle instead of Workbook_Open...

Code:
Private Sub Workbook_Activate()
    MsgBox "Error checking OFF in" & ActiveWorkbook.Name _
        & " Workbook_Activate()"
    Application.ErrorCheckingOptions.NumberAsText = False
End Sub

Private Sub Workbook_Deactivate()
    MsgBox "Error checking ON in" & ActiveWorkbook.Name _
        & " Workbook_Deactivate()"
    Application.ErrorCheckingOptions.NumberAsText = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,816
Messages
6,132,867
Members
449,761
Latest member
AUSSW

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top