Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 120
Default 'BeforeClose' code problems:book won't close if more than one book is open

I'm attempting to reset my workbook on close, but I've introduced
something that prevents Excel from quitting and all workbooks from
closing if I click the application "X" with more than one workbook
open.

My workbook opens on a sheet called "Splash" - if macros are disabled,
there's a message there giving the user instructions on how to use the
workbook. After the user is finished with all activity and closes the
book or quits the program, I want to reset the book back to the Splash
page.

My Personal workbook always opens underneath any Excel session because
I have macros in it. I do not have a BeforeClose macro in Personal.
If I only have thsi workbook and Personal open, everything closes and
quits fine. But if I have one more workbook open, the BeforeClose is
processed and the book opens the Splash sheet, but it won't close and
the application won't quit. Everything just sits there. If I hit the
"X" again, then everything closes.

The purpose of the If statement in the beginning of the code is to
allow the user to get partway into the book, then decide he doesn't
want to continue and quit, and present him with an opportunity to save
where he's at in his processes. I know the message box at the end
always pops up, but I wanted to give the user two chances (if you knew
my users, you'd understand!).

If someone can help me understand what I did to stop everything from
closing and how to do it right, I'd appreciate it.

Ed


Sub Workbook_BeforeClose(Cancel As Boolean)
'Stop
If Me.Saved = False Then
If MsgBox("Do you want to save your changes?", vbYesNo, "Save
Changes To This File?") = vbYes Then
Me.Save
Else
Exit Sub
End If
End If

With Me.Worksheets("Splash")
.Visible = xlSheetVisible
.Activate
.Range("A1").Select
End With

Dim wks As Worksheet
For Each wks In Me.Worksheets
If wks.Name < "Splash" Then wks.Visible = xlSheetHidden
Next wks
Me.Worksheets("Splash").Range("A1").Select
Me.Save

End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need code to close minimized workbooks in BeforeClose event Cheryl Excel Programming 3 August 17th 07 10:53 PM
save Changes and close book Darin Kramer Excel Programming 1 August 13th 07 03:36 PM
Open book, copy and paste from sheet, and then close.... Darin Kramer Excel Programming 5 September 14th 06 04:00 PM
default template (book.xlt) doesn't close Michael Excel Discussion (Misc queries) 3 December 2nd 05 05:13 PM
Open book, check for macros, close book Robin Hammond[_2_] Excel Programming 5 March 31st 05 06:09 PM


All times are GMT +1. The time now is 02:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"