Error handling

  • Thread starter Thread starter GPO
  • Start date Start date
G

GPO

(excel 2000, 2003, 2007)

Hello All

I have a function where I want the error handling for the most part to be
On Error GoTo HandleError

but for certain blocks I want it to be
On Error Resume Next

How do I do this?

Regards

GPO
 
Just switch between the two errors mode as required

On Error GoTo HandleError
'section 1 code
On Error Resume Next
'section 2 code
 
I tend to handle that by placing the Resume Next code into a separate
procedure, as the error handler is reset on exit.

Sub TestError()

On Error GoTo HandleError

'do stuff

Call CalledProc

Debug.Print 1 / 0

Exit Sub

HandleError:
MsgBox Err.Number & " : " & Err.Description
End Sub

Function CalledProc()

On Error Resume Next
Debug.Print 1 / 0
End Function

It may seem unnecessary, but I find it keeps the code more structured, and
gives m e all the control that I need
 
Back
Top