Excel VBA Cancel Closing of Program

Josh Hazel
07-16-2010, 08:49 PM
I have this problem with users who do not fully understand how to use Excel.
Wen you want to close the workbook that is active, you should click on the little "x" button on the workbook. However, users continually click on the big "x" button on the application, which closes their other workbook but it also causes it to close this one and it should not.

Does anyone know a work around for this? I have a couple ideas but don't know how to implement them.

The first would be to cancel on the workbook_close event, but I dont see how you would tell the difference between an intentional close clicking on the workbook and a close by clicking the application X button.

The second is to have it so that no other workbooks can be opened in this instance of the application.

Bob Phillips
07-17-2010, 09:42 AM
You could trap the Workbook_BeforeClose event, and if the workbooks count throw up a MsgBox asking them if they really want to close Excel.

iabbott
07-19-2010, 01:41 AM
can't you get the names of the workbooks that are open, then using the Workbook_BeforeClose event decide for the user which should be closed?

if you have one workbook that should always be open, check if the user is trying to close that one and stop them

or if the open workbook count is greater then 1, cancel the close and then close only the active one

Josh Hazel
07-21-2010, 08:07 PM
Well I did just think up an idea, the workbook is only suppose to close when a specific form closes. So if I add a flag on the spreadsheet true/false to allow closing, i can have the userform close trigger the flag to true and have the beforeclose event check to make sure that value is true... but they also have to set the initialize value to false

however the workbook count option might be an option too, just not quite as specific

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum