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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top