Did you really expect us to figure out the structure you have now described
to us from the description you provided in your original posting?
The problem you are facing is that each subroutine has its own error
handler, so that is where the error is handled at... so no, you can't
control ProcedureA's execution from within them. However, if those other
procedures (ProcedureB, ProcedureC, etc.) did not have any error handlers,
then the error handler in ProcedureA would process the error. Try this.
Comment out each On Error GoTo statement in ProcedureB, ProcedureC, etc. (so
there is effectively no error handling taking place in the individually
called procedures) and use something like this for ProcedureA and see if it
does what you want...
Sub ProcedureA()
Dim ModuleName As String
Dim SubName As String
ModuleName = "Module1"
On Error GoTo SomethingWentWrong
SubName = "ProcedureB"
Call ProcedureB
SubName = "ProcedureC"
Call ProcedureC
SubName = "ProcedureD"
Call ProcedureD
SubName = "ProcedureE"
Call ProcedureE
Exit Sub
SomethingWentWrong:
MsgBox "Something went wrong in " & ModuleName & ", " & SubName
End Sub
--
Rick (MVP - Excel)
RyanH said:
I actually already have that type of structure. But under each procedure I
have I have an Error Handler. For example,
Sub ProcedureA()
On Error GoTo ErrorHandler
Call ProcedureB
Call ProcedureC
Call ProcedureD
Call ProcedureE
Exit Sub
'***********
ErrorHandler:
Call ErrorHandler(ModuleName, SubName)
End Sub
Sub ProcedureB()
On Error GoTo ErrorHandler
' procedure B code here
Exit Sub
'****************
ErrorHandler:
Call ErrorHandler(ModuleName, SubName)
End Sub
Sub ErrorHandler(ModuleName As String, SubName As String)
Msgbox "Something went wrong in " & ModuleName & ", " & SubName
End Sub
I have an On Error GoTo ErrorHandler for each procedure because I want the
Msgbox to display the module name and procedure name the error came from.
In
your example I will not beable to return the SubName.
I was really wanting to know if there is a line of code that I could put
in
the ErrorHandler Procedure to kill the entire macro? Instead of it only
canceling Procedure B and continuing on with the other procedures.