ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can the X to Close button on a workbook be disabled? (https://www.excelbanter.com/excel-programming/295595-can-x-close-button-workbook-disabled.html)

eric

Can the X to Close button on a workbook be disabled?
 
Does anyone know how to use vba code to disable the X to close button on an open workbook. I have placed a command button on a worksheet and do not want the user to be able to close the workbook without clicking the command button.

Harald Staff

Can the X to Close button on a workbook be disabled?
 
Hi

Place in the ThisWorkbook module:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = True
End Sub

Now the workbook can't close at all. You take it from there.

HTH. Best wishes Harald

"Eric" skrev i melding
...
Does anyone know how to use vba code to disable the X to close button on

an open workbook. I have placed a command button on a worksheet and do not
want the user to be able to close the workbook without clicking the command
button.




All times are GMT +1. The time now is 06:47 PM.

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