Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Call Procedure with On Error Statement

Is there a way to call my error handler procedure when an error occurs in any
of my procedures. This is kinda what I was looking for.

Sub Test()

On Error GoTo ErrorHandler(Err.Number)
'my code here

End Sub

Sub ErrorHandler(ByVal intErrorNumber As Integer)

Select Case intErrorNumber
Case 1
'do this
'and so on

End Select

End Sub


--
Cheers,
Ryan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Call Procedure with On Error Statement

The on error statement is leveraging goto which just takes you to a specific
section in the procedure... so you need something like this...

Sub Test()

On Error GoTo ErrorHandler
'my code here
Exit Sub
ErrorHandler:
call MyErrorHandler(Err.Number)
End Sub

Sub MyErrorHandler(ByVal intErrorNumber As Integer)

Select Case intErrorNumber
Case 1
'do this
'and so on

End Select

End Sub

***There is an automated addin that makes generating that code very easy.
Take a look at this link to get the addin. There are a bunch if indispensable
tools in this addin...
http://www.mztools.com/index.aspx
--
HTH...

Jim Thomlinson


"RyanH" wrote:

Is there a way to call my error handler procedure when an error occurs in any
of my procedures. This is kinda what I was looking for.

Sub Test()

On Error GoTo ErrorHandler(Err.Number)
'my code here

End Sub

Sub ErrorHandler(ByVal intErrorNumber As Integer)

Select Case intErrorNumber
Case 1
'do this
'and so on

End Select

End Sub


--
Cheers,
Ryan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Call Procedure with On Error Statement

thats what I figured I had to do. I wasn't sure if there is a way to call
the Error Handler Sub directly.

Thanks.
--
Cheers,
Ryan


"Jim Thomlinson" wrote:

The on error statement is leveraging goto which just takes you to a specific
section in the procedure... so you need something like this...

Sub Test()

On Error GoTo ErrorHandler
'my code here
Exit Sub
ErrorHandler:
call MyErrorHandler(Err.Number)
End Sub

Sub MyErrorHandler(ByVal intErrorNumber As Integer)

Select Case intErrorNumber
Case 1
'do this
'and so on

End Select

End Sub

***There is an automated addin that makes generating that code very easy.
Take a look at this link to get the addin. There are a bunch if indispensable
tools in this addin...
http://www.mztools.com/index.aspx
--
HTH...

Jim Thomlinson


"RyanH" wrote:

Is there a way to call my error handler procedure when an error occurs in any
of my procedures. This is kinda what I was looking for.

Sub Test()

On Error GoTo ErrorHandler(Err.Number)
'my code here

End Sub

Sub ErrorHandler(ByVal intErrorNumber As Integer)

Select Case intErrorNumber
Case 1
'do this
'and so on

End Select

End Sub


--
Cheers,
Ryan

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using a Range variable to call a procedure with a ByVal statement... R Tanner Excel Programming 14 September 18th 08 08:40 PM
Run-time Error '5' - Invalid procedure call or argument Trefor Excel Discussion (Misc queries) 2 December 17th 07 03:32 AM
procedure call error issue Student Excel Programming 2 October 24th 06 04:28 PM
Invalid procedure call or argument error Patrick Simonds Excel Programming 1 August 12th 06 11:40 PM
Run-time error '5':Invalid Procedure call or argument Jan Refsdal Excel Programming 1 July 25th 03 05:14 AM


All times are GMT +1. The time now is 02:54 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"