Exiting a macro while running

Exiting a macro while running

Anonymous
Not applicable
190 Views
2 Replies
Message 1 of 3

Exiting a macro while running

Anonymous
Not applicable
I have made a VB SubRoutine in ThisDrawing that call a Userform. When the user click the X button or my cancel button i want my whole program to stop (the routine in ThisDrawing) what is the command i must use to do this? Thanks, Gis
0 Likes
191 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
Hi,

I am a rank beginner so be careful of the value you place on my suggestions.

Under my "Private Sub CmdCancel_Click()" (CmdCancel=the name of my cancel
button) I set a public boolean variable "Cancel = True" this is then trapped
this in my code when control is passed back to the main subroutine. This
works when you press the cancel button. For this to work with the escape key
you need to set the Cancel property of a command button named "Cancel" or
"Close" to True (then hitting the ESC key will be the same as clicking that
button).

I do not know how to trap the user clicking the X button. I assume that you
could set Cancel = True before you call the userform and set Cancel = false
if the user clicks the X button.

Hope this helps.

Sean


"CIA_GIS" wrote in message
news:f127141.-1@WebX.maYIadrTaRb...
> I have made a VB SubRoutine in ThisDrawing that call a Userform. When the
user click the X button or my cancel button i want my whole program to stop
(the routine in ThisDrawing) what is the command i must use to do this?
Thanks, Gis
>
0 Likes
Message 3 of 3

Anonymous
Not applicable
I'm sure this isn't the cleanest answer, but it's been a long day...

I would do something similar to Sean. In your module in ThisDrawing, put
code such as:

Public boolFormCanceled as boolean
'until user actually pushes OK button, assume the user cancels
boolFormCanceled = True
myForm.show
if boolFormCanceled = true then Exit Sub

In your userform, if you have an OK button that the user clicks to keep
going (assuming it's named btnOK), put the following:

Private Sub btnOK_Click()
boolFormCanceled = False
End Sub

This way, the only way the user can keep the program going is to use the OK
button.

Good luck
0 Likes