View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Stop Procedure when an Error occurs in another procedure

You can use On Error to trap the error. Something like this...

Sub ProcedureA()
On Error GoTo SomethingWentWrong
Call ProcedureB
Cal ProcedureC
Call ProcedureD
Call ProcedureE
Exit Sub
SomethingWentWrong:
' Any clean up code you might need to execute
End Sub

A couple of points to note (although you should look up the On Error
Statement in the help files for comprehensive details)... Use On Error GoTo
and then specify the name of a code label (SomethingWentWrong in the above
example) and then provide a section of code below your main code that starts
with that label name (same naming rules as for variables except that all
code labels require a colon at the end of their name... clues VB into the
fact that it is a label and not the name of a subroutine). After the code
label, you can place any code that you might need to "clean things up"
before exiting you subroutine (or function). The Exit Sub statement
immediately above the code label name is needed to prevent your main code's
execution from "falling through" into your error handling code.

--
Rick (MVP - Excel)


"RyanH" wrote in message
...
Can you stop Procedure A from contiueing to call other procedure if there
is
an error in procedure C?

Sub ProcedureA()

Call ProcedureB
Cal ProcedureC
Call ProcedureD
Call ProcedureE

Ens Sub
--
Cheers,
Ryan