PC Review


Reply
Thread Tools Rate Thread

'BeforeClose' code problems:book won't close if more than one book is open

 
 
Ed from AZ
Guest
Posts: n/a
 
      18th Sep 2007
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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
SAVE A SHEET AS A BOOK, CLOSE IT, CONTINUE VBA CODE - XCL 2003 JingleRock Microsoft Excel Programming 16 20th Jul 2009 01:03 PM
Need code to close minimized workbooks in BeforeClose event =?Utf-8?B?Q2hlcnls?= Microsoft Excel Programming 3 17th Aug 2007 10:53 PM
Open book, copy and paste from sheet, and then close.... Darin Kramer Microsoft Excel Programming 5 14th Sep 2006 04:00 PM
Open book, check for macros, close book CLR Microsoft Excel Programming 8 31st Mar 2005 06:09 PM
Copying Pictures from Book to Book using Code =?Utf-8?B?UGhpbCBXb29k?= Microsoft Excel Programming 0 22nd Mar 2004 07:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:00 AM.