UserForm Issue

madchemist

Board Regular
Joined
Jul 10, 2006
Messages
198
I have a user form that I created that I want to prompt users to make sure they intended to hit a macro button that is not reversible.

After they read the warning, they click Yes or No, or the red X in the upper right corner.

I prompt the warning in the code just using:

Code:
frmWarning.show

So If they click yes, shouldn't I just use the following code to exit the form and have the macro continue?

Code:
Private Sub frmWarning_Click()
  Unload Me
End Sub

Even when they click no or the red x, the macro is continuing. What do I write for the code the kill the macro?

Would I just use Kill, or is there some other command that will stop it? Also, how do I write the code for the red X button?


Thanks!
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi,

You can use a messagebox to ask anything you want.
Code:
Sub test()
Dim response As Integer

response = MsgBox("continue?", vbYesNo, "title")
If response = vbNo Then Exit Sub

MsgBox "macro continues"

End Sub
kind regards,
Erik
 
Upvote 0

QuietRiot

Well-known Member
Joined
May 18, 2007
Messages
1,079
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
  2. MacOS
exit sub = to kill

then in the click part just call the macro you want run
 
Upvote 0

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,358
Office Version
  1. 365
Platform
  1. Windows
To stop all code.
Code:
End
 
Upvote 0

Forum statistics

Threads
1,191,671
Messages
5,987,956
Members
440,121
Latest member
eravella

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top