View Single Post
  #17   Report Post  
Posted to microsoft.public.excel.programming
GS[_6_] GS[_6_] is offline
external usenet poster
 
Posts: 1,182
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?


Start with putting your global var in Module1 to make it public because
ThisWorkbook is a private class.

I'd use an entirely different approach, though, depending on what task this
project is required to do. I'm willing to review your project (if you wish) to
make suggestions and/or pass back sample/example approaches. This requires I
have a working copy of the workbook with a reasonable number of sheets to get
some idea of its magnitude!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion