Minor issue with BeforeClose functionality

jst3712

New Member
Joined
Apr 15, 2010
Messages
10
First of all, I apologise for the lack of, or incorrect, terminology for this query.

Is there any way to bypass code that exists under Workbook 'BeforeClose' event, when required?

Here's what's happening...

I have an "On Error Goto GenErr" in various locations in the project incase there is a problem, which causes a MsgBox to appear and then the workbook closes automatically without saving changes. However, additional code runs via the 'BeforeClose' which I don't want to run unless the user closes the workbook (or Excel) manually.
I have code under BeforeClose that just brings up a different MsgBox (it's like a reminder message requiring user to click yes or no) and if yes is selected, then the workbook continues to close, otherwise remains open.

Any suggestions? Thanks.
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Maybe at the top of a regular module (outside any subs) declare a global variable

Code:
Public NoClose as Boolean

Then in your error handler set that to True

Code:
NoClose = True

Finally, in the BeforeClose routine, right at the top

Code:
If NoClose then Exit Sub
 
Upvote 0
Maybe at the top of a regular module (outside any subs) declare a global variable

Code:
Public NoClose as Boolean
Then in your error handler set that to True

Code:
NoClose = True
Finally, in the BeforeClose routine, right at the top

Code:
If NoClose then Exit Sub


Beautiful... that works! :biggrin: Thank you so much. I tried doing something similar like this the other day but failed. Jason.

--- RESOLVED ---
 
Upvote 0

Forum statistics

Threads
1,214,883
Messages
6,122,077
Members
449,064
Latest member
MattDRT

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