Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default userform cancel button

I have a cancel button in a userform. The code in the form unloads the
userform. But I want the cancel button to end the main macro too. I've
tried numerous conbinations of

if cbCancel then exit sub

and a dozen others. None of them work. They either cancel the program
even if the Cancel button isn't clicked, or don't exit when it is. I
did a google search here and found a number of routines, none of which
seemed to apply to my situation (I don't need to check and see if the
person speaks English to exit. I want my users to be able to exit even
if they don't speak English!). Can someone give me some simple code to
put in my macro to close the program if the cbCancel command button has
been clicked?

Thanks for the help!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default userform cancel button

Hi Dave,

Try something like:

In a standard module:

Option Explicit
Public blCancelled '<<=== Before any subs

'=============
Public Sub Tester001()

blCancelled = False
UserForm1.Show

If blCancelled Then Exit Sub
'Other code, e.g.:
MsgBox "Hi"

End Sub
'<<=============

In the Userform module:

'=============
Private Sub cbCancel_Click()
blCancelled = True
Unload Me
End Sub
'<<=============


---
Regards,
Norman


"davegb" wrote in message
oups.com...
I have a cancel button in a userform. The code in the form unloads the
userform. But I want the cancel button to end the main macro too. I've
tried numerous conbinations of

if cbCancel then exit sub

and a dozen others. None of them work. They either cancel the program
even if the Cancel button isn't clicked, or don't exit when it is. I
did a google search here and found a number of routines, none of which
seemed to apply to my situation (I don't need to check and see if the
person speaks English to exit. I want my users to be able to exit even
if they don't speak English!). Can someone give me some simple code to
put in my macro to close the program if the cbCancel command button has
been clicked?

Thanks for the help!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default userform cancel button


davegb wrote:
I have a cancel button in a userform. The code in the form unloads the
userform. But I want the cancel button to end the main macro too. I've
tried numerous conbinations of

if cbCancel then exit sub

and a dozen others. None of them work. They either cancel the program
even if the Cancel button isn't clicked, or don't exit when it is. I
did a google search here and found a number of routines, none of which
seemed to apply to my situation (I don't need to check and see if the
person speaks English to exit. I want my users to be able to exit even
if they don't speak English!). Can someone give me some simple code to
put in my macro to close the program if the cbCancel command button has
been clicked?

Thanks for the help!


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 573
Default userform cancel button

Thanks, was exactly what I was looking for.

davegb wrote:
I have a cancel button in a userform. The code in the form unloads the
userform. But I want the cancel button to end the main macro too. I've
tried numerous conbinations of

if cbCancel then exit sub

and a dozen others. None of them work. They either cancel the program
even if the Cancel button isn't clicked, or don't exit when it is. I
did a google search here and found a number of routines, none of which
seemed to apply to my situation (I don't need to check and see if the
person speaks English to exit. I want my users to be able to exit even
if they don't speak English!). Can someone give me some simple code to
put in my macro to close the program if the cbCancel command button has
been clicked?

Thanks for the help!


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 get userform Cancel button to invoke Exit Sub in calling macro? Craig Remillard New Users to Excel 1 November 19th 09 03:55 AM
Userform SetFocus with Exit and Cancel Neal Excel Programming 3 January 31st 06 01:21 AM
Cancel button to cancel the whole macro excelnut1954 Excel Programming 3 January 17th 06 08:27 PM
Cancel a Procedure through a Userform jumpjump[_3_] Excel Programming 1 August 30th 05 09:52 AM
Cancel Button on Userform KJ Dahl Excel Programming 2 December 19th 04 07:47 PM


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