ending vba

A

Arnold Klapheck

I am sure this is super simple but cannot find it anywhere.

I am running subs that call on a list of other subs, I want to test
something and stop vba from running. So far it just exits the sub I am in and
continues to run the next sub. How do I shut down VBA completly and take user
back to the Excel Spreadsheet?

If PName = "" Then
x = MsgBox("You must enter a Participant Name", vbCritical, "Error")
Application.Goto Sheets("Program Controls").Range("ParticipantName"),
True
'Here I want to stop running ALL VBA code not just this subroutine
End If
 
B

Bob Phillips

You could use

End

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
J

Jim Thomlinson

You could change your subs into functions that return booleans. Something
like this...

sub DoLotsOfStuff
if DoThis = false then exit sub
if DoThat = false then exit sub
msgbox "Everything went ok"
end sub

Function DoThis() as boolean
DoThis = True
if False then
DoThis = False
exit function
end if
End Function

Function DoThat() as boolean
DoThat= True
if true then
DoThat= False
exit function
end if
End Function
 
J

Jim Thomlinson

You should note that End clears any global variables and objects... This may
or may not be an issue.
 
A

Arnold Klapheck

thanks, I knew it would be simple, I was thinking I had to put something
after end.
 

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