Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default Workbook_BeforeClose Event and Cancel Option

The following below displays a message when a workbook is closed. However if
the user hits the cancel button when prompted with the options prior to
close, this code still creates the message. This is becuase this event is
triggered before the user is presented with the close options. How do you
get around this. Is there another event that I can use to verify if in fact
the file has been closed.


Private Sub Workbook_BeforeClose(Cancel As Boolean)

If Cancel = False Then
Msgbox("Book closed")
End If

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Workbook_BeforeClose Event and Cancel Option


Yes of course they will, you need to substitute one of the message boxes
with your desired action, to cancel the operation or show the workbook
as Saved or save the workbook.

Excel Monkey;309492 Wrote:
This works but the user will then be prompted again with the Windows
message
box as well.

Thanks

EM

"Simon Lloyd" wrote:


Perhaps, rather than that statement maybe capture the cancel from

your
on message box something like:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim MyBox
Cancel = False
MyBox = MsgBox("Close Workbook?", vbYesNoCancel, "Select an action")
If MyBox = vbNo Then
MsgBox "No"
ElseIf MyBox = vbYes Then
MsgBox "Yes"
ElseIf MyBox = vbCancel Then
MsgBox "Cancel"
End If
End Sub

Excel Monkey;309397 Wrote:
The following below displays a message when a workbook is closed.
However if
the user hits the cancel button when prompted with the options

prior to
close, this code still creates the message. This is becuase this

event
is
triggered before the user is presented with the close options. How

do
you
get around this. Is there another event that I can use to verify if

in
fact
the file has been closed.


Private Sub Workbook_BeforeClose(Cancel As Boolean)

If Cancel = False Then
Msgbox("Book closed")
End If

End Sub



--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' ('The Code Cage' (http://www.thecodecage.com))

------------------------------------------------------------------------
Simon Lloyd's Profile: 'The Code Cage Forums - View Profile: Simon

Lloyd' (http://www.thecodecage.com/forumz/member.php?userid=1)
View this thread: 'Workbook_BeforeClose Event and Cancel Option - The

Code Cage Forums'
(http://www.thecodecage.com/forumz/sh...ad.php?t=86505)




--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=86505

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
Workbook_BeforeClose(Cancel As Boolean) - Cancel won't work gpmichal Setting up and Configuration of Excel 1 May 12th 09 02:33 AM
Workbook_BeforeClose Event and Cancel Option Simon Lloyd[_1091_] Excel Programming 1 April 15th 09 08:18 PM
Workbook_BeforeClose: Cancel doesn't work sebt Excel Programming 2 February 23rd 06 10:50 AM
Workbook_BeforeClose - Cancel not working sebt Excel Programming 0 January 31st 06 04:36 PM
Detecting a cancel on Workbook_BeforeClose event? Don Wiss Excel Programming 3 January 18th 05 12:49 PM


All times are GMT +1. The time now is 11:19 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"