I am trying to close an application when the user clicks either the Red X, a button. Previously I used code below to close the application, when the button was clicked. It worked as expected. Here is the code:
Code:
Sub Exit_Referrals()
Dim MsgBoxResult As Long
MsgBoxResult = MsgBox("Would you like to Exit the Referral Workbook?" & vbCr, _
vbYesNo, "Voc. Rehab. - Referral")
If MsgBoxResult = vbNo Then
Exit Sub
ElseIf MsgBoxResult = vbYes Then
Sheets("TOC").Select
Application.Calculation = xlCalculationAutomatic
Application.Quit
ThisWorkbook.Close SaveChanges:=True
End If
End Sub
When i tried to activate the code, when the Red X, was clicked, I ran into some problems. 1) You are asked if you want to exit the application 2x; 2) The application closes, but Excel remains open; 3) if you choose No (remain open),the application closes. I have the same problem when the button is clicked. Here is the current code:
This is located on thisworkbook
Code:
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Exits application
Call Exit_Referrals
End Sub
The
Sub Exit_Referrals() is located in module 1. I know I am missing something, but it escapes me.