Quitting Macro

K

Ken Hudson

I have a macro that includes many message boxes that lead to sub-routines.
E.g.:

.....
If MsgBox("Do you have an F854 this month?", vbYesNo) = vbYes Then
Call ImportF854
End If
......

I want to build in an option that would allow the user to quit the macro at
any of these prompts. I want to give the user the instruction that they could
enter a "^" character for example at the message prompt and the macro would
then close. Is there a "graceful" way to code this?
 
G

Gary Keramidas

you can try this

If MsgBox("Do you have an F854 this month?", vbYesNo) = vbYes Then
Call ImportF854
else
exit sub
End If
 
T

Tom Ogilvy

Why not use VbYesNoCancel

Dim lAns as Long
lAns = MsgBox("Do you have an F854 this month?" & _
vbNewline & "Hit cancel to quit", vbYesNoCancel)
if lAns = vbYes then
Call ImportF854
elseif lAns = vbCancel then
exit sub
End If
 
K

Ken Hudson

That will work.
Thanks Tom.

--
Ken Hudson


Tom Ogilvy said:
Why not use VbYesNoCancel

Dim lAns as Long
lAns = MsgBox("Do you have an F854 this month?" & _
vbNewline & "Hit cancel to quit", vbYesNoCancel)
if lAns = vbYes then
Call ImportF854
elseif lAns = vbCancel then
exit sub
End If
 

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