Exiting a Sub in Word 2003

A

Alan Stancliff

Here's another VBA question for the Word 2003 macro experts.

Suppose I have a macro like this:

Sub MyWondrousInvention()
Userform_1_FRM.Show
Userform_2_FRM.Show
End Sub

As you can guess, the two items that "Show" are two user forms. The
first user form has a CANCEL button on it, and the code looks like this:

Private Sub ExitCMD_Click()
Userform_1_FRM.Hide
Unload Userform_1_FRM
End Sub

What I would like is that if the first user form exits because the
CANCEL button is pressed, the second user form does not and the
MyWondrousInvention sub is exited without the second step being
activated. But because the click routine is private, I can't figure out
how to make it abort the rest of the sub. I suppose some if-else-then
routine, but how does one do it in this case?

Regards,

Alan Stancliff
 
G

Graham Mayor

Wouldn't it make more sense to have

Sub MyWondrousInvention()
Userform_1_FRM.Show
End Sub

and

Private Sub ExitCMD_Click()
Unload Me
Userform_2_FRM.Show
End Sub

with additional sub routines called as required from each of the two user
forms?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Alan Stancliff

Hi Graham,

Yup, it probably would make more sense. I'm going to play with it a bit
more tonight after work (I work weekends).

Thanks.

Regards,

Alan Stancliff
 
A

Alan Stancliff

I got it working now, Graham. It was much simpler than I thought. I
thought I would have to figure out some way of passing a value from a
private sub that was not even a function to a public one.

Regards,

Alan Stancliff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top