One IF, Two THENS

B

BEEJAY

The following does close the active workbook, but it also needs to
totally exit all current sub as well as the call procedure this is part of?
any ideas?

Sub NotAllowed()
Dim Msg As String, Title As String
Dim Config As Integer, ans As Integer
Msg = " This process may NOT be used on an "
Msg = Msg & vbNewLine & vbNewLine
Msg = Msg & " 'E-Mail Safe' File"
Msg = Msg & vbNewLine & vbNewLine
Msg = Msg & " Please click on OK"
Msg = Msg & vbNewLine & vbNewLine
Msg = Msg & " You will be exited from this procedure"
Msg = Msg & vbNewLine & vbNewLine
Config = vbOKOnly = vbExclamation
ans = MsgBox(Msg, Config, Title)

If ans = vbOK Then ActiveWorkbook.Close
' Somehow require an end or exit here
 
T

Tom Ogilvy

You can put a simple

If ans = vbOK Then
ActiveWorkbook.Close Savechanges:=False
END
End if
End Sub

but that does an immediate termination of code including wiping out any
global variables. Most advise against such an approach. Better would be
to design you procedure to return a value and test for that value in the
calling sub and likewise up the chain of callin subs if that is required.

Another alternative is to put in an error handler in the highest level
calling sub and no where else. then raise an error in this procedure and
have the error handler terminate the procedure.
The error will climb the call stack looking for the first available error
handler routine.
 

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

Similar Threads


Top