sassriverrat
Well-known Member
- Joined
- Oct 4, 2018
- Messages
- 655
Good Morning,
I wrote this piece of code to attempt to close excel if the userform "X" is used to close the userform. Basically the userform opens when excel does and asks for one of two buttons. If neither button is pushed (i.e. someone closes the userform), then I want excel to close.
please note that clicking either of the buttons in the userform unloads it so I tried an Userform_Terminate() and had a terrible time getting the workbook back open to delete that...
I wrote this piece of code to attempt to close excel if the userform "X" is used to close the userform. Basically the userform opens when excel does and asks for one of two buttons. If neither button is pushed (i.e. someone closes the userform), then I want excel to close.
please note that clicking either of the buttons in the userform unloads it so I tried an Userform_Terminate() and had a terrible time getting the workbook back open to delete that...
Code:
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)MsgBox "Do you really want to close?", vbYesNoCancel
If vbYes Then
'Application Closer
If Workbooks.Count > 1 Then
ActiveWorkbook.Close
Else: Application.Quit
End If
Else: Exit Sub
End If
End Sub