Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default ThisWorkBook BeforeClose Event

Carlos I use the Auto_Close() event to get rid of a toolbar.

as I think this code is always run before the workbook shuts down

Sub Auto_Close()

On Error Resume Next
CommandBars("Name").Delete '<<<<< change name to name of toolbar

With ActiveWorkbook
.RunAutoMacros xlAutoClose
.Close
End With
End Sub

It's not quite what you want but you vould adapt this

Dim msg, Style, Title, Response
msg = "Close the model" ' Define message."

Style = vbYesNoCancel + vbExclamation + vbDefaultButton2 ' Define buttons.
Title = "Selection" ' Define title.
'Display message.
Response = MsgBox(msg, Style, Title)
If Response = vbYes Then ' User chose Yes.
Call Auto_Close
End If

If Response=VbNo then
Exit sub
End if

If Response=VbCancel then
Exit Sub
End if



"Carlos Lozano" wrote in message
...
Hi,

My application creates a toolbar on Opening (this works fine) and I am

trying to delete it when the workbook is closed. I am calling the Toolbar's
delete method on the BeforeClose event of the ThisWorkBook Object.

The current behavior is below:
1) If the document was not modified, it works perfectly
2) If the document was modified, it prompts to save changes and if "yes"

or "No" are selected works fine. The BeforeClose event is executed as
expected.
2) If the document was modified, and "cancel" is selected the BeforeClose

event is executed. I wasn't expecting this as the workbook was not closed.
So, It deletes the toolbar and the workbook remains open (with no toolbar
which is a problem). The beforeClose event is executed before the message is
shown.

How can I know what was selected on the "Do you want to save..." message?

to choose the right action.

Thank you,

Carlos Lozano
CAX IT Services




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
How to keep spreadsheet open in the BeforeClose event Wellie[_2_] Excel Programming 3 February 29th 04 09:03 PM
Workbook_Beforeclose vs BeforeClose Event Juan Pablo González Excel Programming 3 February 2nd 04 12:17 AM
File won't close when "beforeclose" event is used. David G[_3_] Excel Programming 4 December 8th 03 04:22 AM
Cancelling the BeforeClose Event Troy[_5_] Excel Programming 6 December 2nd 03 06:40 AM
BeforeClose event - Savings Mike[_40_] Excel Programming 3 September 24th 03 11:33 AM


All times are GMT +1. The time now is 12:45 AM.

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

About Us

"It's about Microsoft Excel"