# Office 365 >  >  Disabling the X button stops Excel from saving and closing

## KSChan

Hi Excel experts, I need your help.
I created an EXIT button for user to close the worksheet (and also to save it) instead of using the X button.
However, it seems to prevent my EXIT button from saving the worksheet and exiting Excel.
I've attached a sample file to show what happened.
Please help me to solve this puzzling problem.

Thank you.
Chan K.S.

----------


## Logit

.



```
Please Login or Register  to view this content.
```

----------


## KSChan

Thank you, Logit for the quick reply.
When I followed your suggestion to change "Case Is = vbYes" to "Case vbYes", it still didn't work.
I added "Public CloseMode As Boolean" to the coding for the EXIT macro and now I can close the worksheet and exit Excel by clicking YES option.
However, when I included an Option for CANCEL, clicking on it or the YES option will NOT close the worksheet nor exit Excel.
Any suggestion? Or should I forget about including the CANCEL option. It seems that 'something' is preventing the worksheet from closing without being saved (which I wanted for this option).
Thanks again.

----------


## Logit

.
Here is the revised code and a sample workbook :




```
Please Login or Register  to view this content.
```

----------


## KSChan

Thanks, Logit. It works for both YES and NO options.
But I also want user not to use the X button.
In the ThisWorkbook, I have the following code and Excel doesn't close on both YES and NO options!




```
Please Login or Register  to view this content.
```


I wonder why the code in ThisWorkbook is causing this! Perhaps it is exit is either by using my own EXIT button or using the X button. Cannot have both!

----------

