I suspect there is some difference between the code you posted and your actual code.
It should always work, and even prevent your button code from closing the workbook since the variable CloseBook will always be False when you test it.
If you had set Application.EnableEvents = False then you would get the Save changes dialog on subsequent attempts to close.
Bill
I appreciate your help but it does not work. I have slightly modified the code and declared Event Enabler as True as first line in the code. I have done it on a fresh file to test but fails. I am reproducing the complete code below.
In Thisworkbook
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.EnableEvents = True
Cancel = Not ok2Close
End Sub
In Module
Public ok2Close As Boolean
Sub CloseMacro()
Application.EnableEvents = True
ok2Close = True
ThisWorkbook.Close SaveChanges:=True
Application.Quit
ok2Close = False
End Sub
It fails second time when I try through X application button. I am ready to send the file if you can share E-mail address.
Thanks in advance.
JC_56