Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default How to get out of BeforeClose event without closing?

Excel 2002
Windows XP Pro SP 2

I am trying to simulate one of those "Do you really, REALLY want to close
this workbook" messages when a user tries to close a workbook. I am using a
message box with the vbYesNo constant and I can successfully determine if
Yes or No was clicked. If the user selects "No", which in my case would be
to NOT close the workbook, how do I get out of the BeforeClose event without
closing?

All help appreciated.

Thanks!

-gk-


=================================================
The creative act is not the province of remote oracles or rarefied geniuses
but a transparent process that is open to everyone.
-Greg Kot in Wilco Learning How To Die-


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 618
Default How to get out of BeforeClose event without closing?

Hi gk

like this

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If MsgBox("yes or no", vbYesNo) = vbNo Then
Cancel = True
End If
End Sub

Cheers
JulieD

"42N83W" wrote in message
...
Excel 2002
Windows XP Pro SP 2

I am trying to simulate one of those "Do you really, REALLY want to close
this workbook" messages when a user tries to close a workbook. I am using
a message box with the vbYesNo constant and I can successfully determine
if Yes or No was clicked. If the user selects "No", which in my case
would be to NOT close the workbook, how do I get out of the BeforeClose
event without closing?

All help appreciated.

Thanks!

-gk-


=================================================
The creative act is not the province of remote oracles or rarefied
geniuses
but a transparent process that is open to everyone.
-Greg Kot in Wilco Learning How To Die-



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default How to get out of BeforeClose event without closing?

Hi

As first line in the event use Cancel = true

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim answer
Cancel = True
answer = MsgBox("do you want to close", vbYesNo, "something")
If answer = vbOK Then
ThisWorkbook.Close
Else
'do nothing
End If
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl



"42N83W" wrote in message ...
Excel 2002
Windows XP Pro SP 2

I am trying to simulate one of those "Do you really, REALLY want to close this workbook" messages when a user tries to close a
workbook. I am using a message box with the vbYesNo constant and I can successfully determine if Yes or No was clicked. If the
user selects "No", which in my case would be to NOT close the workbook, how do I get out of the BeforeClose event without closing?

All help appreciated.

Thanks!

-gk-


=================================================
The creative act is not the province of remote oracles or rarefied geniuses
but a transparent process that is open to everyone.
-Greg Kot in Wilco Learning How To Die-



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default How to get out of BeforeClose event without closing?

Oops, Why don't i test first<g

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim answer
answer = MsgBox("do you want to close", vbYesNo, "something")
If answer = vbYes Then
'close
Else
Cancel = True
End If
End Sub



--
Regards Ron de Bruin
http://www.rondebruin.nl



"Ron de Bruin" wrote in message ...
Hi

As first line in the event use Cancel = true

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim answer
Cancel = True
answer = MsgBox("do you want to close", vbYesNo, "something")
If answer = vbOK Then
ThisWorkbook.Close
Else
'do nothing
End If
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl



"42N83W" wrote in message ...
Excel 2002
Windows XP Pro SP 2

I am trying to simulate one of those "Do you really, REALLY want to close this workbook" messages when a user tries to close a
workbook. I am using a message box with the vbYesNo constant and I can successfully determine if Yes or No was clicked. If the
user selects "No", which in my case would be to NOT close the workbook, how do I get out of the BeforeClose event without
closing?

All help appreciated.

Thanks!

-gk-


=================================================
The creative act is not the province of remote oracles or rarefied geniuses
but a transparent process that is open to everyone.
-Greg Kot in Wilco Learning How To Die-





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 19
Default How to get out of BeforeClose event without closing?

Thank You both Julie and Ron.

It didn't even occur to me to look at the argument of the BeforeClose event,
and I should know better! Setting Canel = True did the trick.

Thanks again!

-gk-

"42N83W" wrote in message
...
Excel 2002
Windows XP Pro SP 2

I am trying to simulate one of those "Do you really, REALLY want to close
this workbook" messages when a user tries to close a workbook. I am using
a message box with the vbYesNo constant and I can successfully determine
if Yes or No was clicked. If the user selects "No", which in my case
would be to NOT close the workbook, how do I get out of the BeforeClose
event without closing?

All help appreciated.

Thanks!

-gk-


=================================================
The creative act is not the province of remote oracles or rarefied
geniuses
but a transparent process that is open to everyone.
-Greg Kot in Wilco Learning How To Die-





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
problem with beforeclose event Gordon Excel Programming 1 September 30th 04 11:21 PM
ThisWorkBook BeforeClose Event Doug Glancy Excel Programming 0 July 29th 04 12:36 AM
ThisWorkBook BeforeClose Event David Adamson[_4_] Excel Programming 0 July 29th 04 12:32 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 06:04 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"