Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default Cancel terminate event??

"Pop" wrote in message
...
I wonder how to cancel a terminate event?
If I invoke a terminate event by pressing the X button on the top right

corner, then I ask does user really want to terminate,
then how am I going to cancel the terminate event if user click no?


Hi Pop,

You can't cancel the Terminate event of a UserForm. Once your code has
reached that point it's too late. What you need to trap is the QueryClose
event instead. This event fires when anything attempts to close the UserForm
and gives you the option to cancel. Here's a basic example:

Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
' If our code is not closing the form, ask the
' user if this is really what they want to do.
If CloseMode < vbFormCode Then
If MsgBox("Do you want to close", vbYesNo) = vbNo Then
Cancel = True
End If
End If
End Sub

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *



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
Cancel sheet change event NSK Charts and Charting in Excel 1 July 17th 07 08:25 PM
terminate a form tkaplan Excel Discussion (Misc queries) 5 October 24th 05 01:14 PM
Macros terminate early Pierre[_3_] Excel Programming 5 January 23rd 04 05:54 PM
Can't terminate the excel instance from VB Gerhard[_2_] Excel Programming 1 July 16th 03 11:06 AM


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