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.
 

Some videos you may like

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

VoG

Legend
Joined
Jun 19, 2002
Messages
63,651
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
 

jst3712

New Member
Joined
Apr 15, 2010
Messages
10
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 ---
 

Watch MrExcel Video

Forum statistics

Threads
1,099,774
Messages
5,470,707
Members
406,718
Latest member
waseem11

This Week's Hot Topics

Top