Alright, here's what I want to do:
I have a main workbook whose 'close' event is fired when the "X" is pressed to close excel. At the time, the focus is on another workbook (opened via the first one with code)
I have tried and tried and tried but no matter what I do I either end up with:
The workbooks close IFF I'm focused on the main workbook
The main workbook won't close when focused on second workbook
(tried moving focus to first workbook first, no effect)
Excel crashes
Some code:
VB Code:
On Error Resume Next Dim Wkb As Workbook Static Recurse As Boolean If Recurse Then Exit Sub End If 'temp code to stop bug 'preferably save and close the whole program or just that workbook 'grey bar shows up if just close that workbook If WkbIntro.Name <> ActiveWorkbook.Name Then MsgBox "timbrplans can only be closed from the intro page.", vbExclamation, "timbrplans" Cancel = True Exit Sub End If 'sets updating, events to false, and status bar to "..." Safety.SetSettings False, False, True, "Shutting Down..." 'Just closing the program here, no real effect CheckSystemData Recurse = True EnableKeys True EnableMenus True Application.Caption = "Excel" 'Save and close all of our workbooks 'by checking if they are open For Each Wkb In Workbooks Select Case LCase(Wkb.Name) Case "tbm_intro.xls" Case "tbm_homes.xls", "tbm_swing.xls", "tbm_sheds.xls", _ "tbm_backyardorganizer.xls", "tbm_decks.xls", _ "tbm_Bunkie.xls", "tbm_estimator.xls", "tbm_garages.xls" SaveMe Wkb Wkb.Close False Case Else Cancel = True End Select Next Wkb SaveMe ThisWorkbook 'default settings for next excel run Safety.RestoreSettings 'if an unknown workbook was open, dont kill all of excel If Cancel Then Application.WindowState = xlNormal ThisWorkbook.Close False End If




Reply With Quote