![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Mar 2002
Posts: 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. |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Sydney, Australia
Posts: 2,908
|
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 |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Mar 2002
Posts: 162
|
Right!
This works. I thank you a lot! Cheers. [ This Message was edited by: Dinictus on 2002-04-24 06:38 ] |
|
|
|
|
|
#4 |
|
New Member
Join Date: Apr 2002
Location: Lawrence, KS
Posts: 29
|
you can also turn off events with
application.enableevents = false don't foget to turn them back on. |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|