ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Prevent a workbook being closed with the X (https://www.excelbanter.com/excel-programming/334819-prevent-workbook-being-closed-x.html)

Mark

Prevent a workbook being closed with the X
 
I am using Excel 97. Is there anyway that you can prevent users on a
workbook from closing the workbook with the 'X' in the top right hand corner?

Thanks
--
Mark

Jim Thomlinson[_4_]

Prevent a workbook being closed with the X
 
In the "thisworkbook" module add a BeforeClose event something like this

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = True
MsgBox "This is not how you close this workbook..."
End Sub

Then in the close button or however you intend to close the workbook add in an
Application.enableevents = false to keep this code from firing when you
really want to clost the book. (Just as a note I usually try to avoid doing
things like this because the users find it fraustrating when they can't close
a program through normal windows functions. They start doing things like
hitting the power button or going into the task manager and ending things)
--
HTH...

Jim Thomlinson


"Mark" wrote:

I am using Excel 97. Is there anyway that you can prevent users on a
workbook from closing the workbook with the 'X' in the top right hand corner?

Thanks
--
Mark



All times are GMT +1. The time now is 02:54 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com