Skip workbookbefore_close sub: how

Dinictus

Board Regular
Joined
Mar 19, 2002
Messages
162
I have a file with a nice workbook_beforeclose sub in it. In this sub some cells are checked for their contents and if the contents is not correct the sheet will not close.

However, I want to insert a button with which people can exit the sheet anyways.
Now I have a activeworkbook.close statement behind this button but then ofcourse the workbookbefore_close sub stops the file from being closed.

Can I somehow program the button to skip the workbook_beforeclose sub?

thnks, I hope someone can help me.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Hi,

One way you could do it is to declare a variable in a standard module as Public e.g.

Public OKToClose As Boolean

Then in your command button code put this:-

OKToClose = True

Then in your Workbook_Close subroutine put this:-

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If OKToClose = True Then Exit Sub

'Rest of your code
End Sub


HTH,
Dan
 
Upvote 0
Right!

This works. I thank you a lot!

Cheers.
This message was edited by Dinictus on 2002-04-24 06:38
 
Upvote 0
you can also turn off events with
application.enableevents = false
don't foget to turn them back on.
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,824
Members
449,050
Latest member
Bradel

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