View Single Post
  #16   Report Post  
FrancisM FrancisM is offline
Junior Member
 
Posts: 14
Default Using the red X (Upper right hand corner) for another purpose.

I don't know if that link worked, so here is the current code:
This is located in ThisWorkbook & does work.


Public fMacro As Boolean
Private Sub Workbook_BeforeClose(cancel As Boolean)
'Part of code to call a pop up calendar.
On Error Resume Next
Application.OnKey "+^{C}"
Application.CommandBars("Cell").Controls("Insert Date").Delete
Dim Msg As String, Ans As Variant
'Cancels The Red X on both the Application & the "Click....." window.
If Not fMacro Then cancel = True
'Reminds the user to click Exit button to close.
Msg = "Click Exit to close."
Ans = MsgBox(Msg, vbInformation, "Vocational Services Database - " & ActiveSheet.Name)
Select Case Ans
Case vbYes
End Select
End Sub

This portion of the code is located in Module 1:

Option Explicit

Sub Exit_Referrals()
Dim Msg As String, Ans As Variant
Msg = "Would you like to Exit the Referral Workbook?"
Ans = MsgBox("Would you like to Exit the Referral Workbook?" & vbCr, vbYesNo, "Vocational Services Database - " & ActiveSheet.Name)
Select Case Ans
ThisWorkbook.fMacro = True
Case vbYes
Sheets("TOC").Select
Application.Calculation = xlCalculationAutomatic
ThisWorkbook.Save
Application.Quit
End Select
End Sub

If I use the active X Button (the way I want to close) a error message arrears:
Compile error: "Statements and labels invalid between Select Case and first Case" What can you suggest that I look at?

I tried changing ThisWorkbook.fMacro = True to If Not fMacro Then cancel = False

The message I get now is Variable not defined. Any suggestions?