ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Any vba code to disable only close button in Excel workbook, please? (https://www.excelbanter.com/excel-programming/361606-any-vba-code-disable-only-close-button-excel-workbook-please.html)

Bon

Any vba code to disable only close button in Excel workbook, please?
 
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


Executor

Any vba code to disable only close button in Excel workbook, please?
 
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



All times are GMT +1. The time now is 12:09 PM.

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