Any vba code to disable only close button in Excel workbook, please?

B

Bon

Dear all

Could anyone give me some sample code on disabling the close button in
Excel workbook?

I tried the Tool -> Protect -> Check Windows method. But, it will
disable the maximize and
minimize buttons as well. Moreover, it will minimize the workbook.

Please give me some advices. thanks


Cheers
Bon
 
E

Executor

Hi,

You can use the BeforeClose event of the worrkbook using VBA:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If MsgBox("Are you sure", vbQuestion + vbYesNo, "Close the book") =
vbNo Then
Cancel = True
End If
End Sub

If you use it like this

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

You will nevere be able to close the workboor or end Excel on a normal
way!

HTH

Executor
 

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

Top