Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 175
Default Cancel button to cancel the whole macro

I have UserForm1, that when completed, and the user clicks the OK
button, opens up UserForm2.
I also have a Cancel option in UserForm1.

Right now, if Cancel is clicked, the macro will still continue on to
UserForm2. That's because the only code I have in the Cancel sub is to
close UserForm1.

I want it to stop the whole macro when Cancel is selected.
What is the correct code I should enter in the Cancel sub to make the
whole macro stop?

Thanks,
J.O.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Cancel button to cancel the whole macro

Why not just Unload the other from as well?

--
HTH

RP
"excelnut1954" wrote in message
ups.com...
I have UserForm1, that when completed, and the user clicks the OK
button, opens up UserForm2.
I also have a Cancel option in UserForm1.

Right now, if Cancel is clicked, the macro will still continue on to
UserForm2. That's because the only code I have in the Cancel sub is to
close UserForm1.

I want it to stop the whole macro when Cancel is selected.
What is the correct code I should enter in the Cancel sub to make the
whole macro stop?

Thanks,
J.O.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Cancel button to cancel the whole macro


In the userform:

Private Sub cmdExit_Click()
Call exitMacro
End Sub

In the Main Module (for reference by both userforms if necessary...._

Public Sub exitMacro()
' quit the macro and exit Excel
Dim msg, style, title, response

If langChoice = "English" Then
msg = "If you exit the application, any unsaved data or
documents" _
& vbCrLf & " will be lost. Are you sure you wish to Exit?"
title = "Please confirm selected action."
style = vbYesNo + vbQuestion + vbDefaultButton1 +
vbApplicationModal
response = MsgBox(msg, style, title)
End If

If response = vbYes Then
exitNo = 0
Application.Quit
End
ElseIf response = vbNo Then
exitNo = 1
End If
End Sub


The message box is just a polite way of reminding the user, they'll
lose everything if they quit.


--
ljsmith


------------------------------------------------------------------------
ljsmith's Profile: http://www.excelforum.com/member.php...o&userid=30531
View this thread: http://www.excelforum.com/showthread...hreadid=501832

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
Workbook_BeforeClose(Cancel As Boolean) - Cancel won't work gpmichal Setting up and Configuration of Excel 1 May 12th 09 02:33 AM
Cancel Macro is user selects 'cancel' at save menu Mark Excel Programming 1 April 6th 05 05:45 PM
Cancel Button Matt Excel Programming 3 February 3rd 04 11:23 PM
Button To Cancel Macro Bill Lunney Excel Programming 0 July 16th 03 10:27 PM


All times are GMT +1. The time now is 02:12 PM.

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"