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

E

Eric

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.
 
H

Harald Staff

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 said:
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.
 
Top