Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
"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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Workbook_BeforeClose(Cancel As Boolean) - Cancel won't work | Setting up and Configuration of Excel | |||
Cancel sheet change event | Charts and Charting in Excel | |||
terminate a form | Excel Discussion (Misc queries) | |||
Macros terminate early | Excel Programming | |||
Can't terminate the excel instance from VB | Excel Programming |