Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
On Error Command
Hi all,
I was wondering if there was a way to do some sought of global On Error Command because all I need is for it to pop up with the same message and to go throughout all of my forms & modules and put on the On Error Command and with the Error Trapping in all of my proceedures? Jason |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
On Error Command
Jason,
There no simple "On Error Call ThisRoutine" that you can use in VBA. But if the top most (first) routine has an error handler active, with the "On Error GoTo [Handler]" syntax, errors will bubble up to from called routines, if they do not deal with the error themselves. You can see what happens if you comment out the line On Error GoTo CommandButton1_Error If you need error handling added to all your routines, I believe MZTools provides a simple way of this. http://www.mztools.com/index.htm Private Sub CommandButton1_Click() On Error GoTo CommandButton1_Error Call FunctionWithHandler Call FunctionWithOutHandler 'Call AnyOtherRoutine Exit Function CommandButton1_Error: Select Case Err.Number Case vbObjectError + 514 MsgBox "Error from " & Err.Source Resume Next Case vbObjectError + 515 MsgBox "Error from " & Err.Source Case Else MsgBox "Error from " & Err.Source End Select End Sub Private Function FunctionWithHandler() As Long On Error GoTo FunctionWithHandler_Error 'Force an error Err.Raise vbObjectError + 513, "FunctionWithHandler", "Handled in this routine" 'Force an error Err.Raise vbObjectError + 514, "FunctionWithHandler", "Not handled in this routine" FunctionWithHandler = 1 Exit Function FunctionWithHandler_Error: Select Case Err.Number Case vbObjectError + 513 'Handle the error somehow Resume Next Case Else 'Pass the error up to the next active error handler Err.Raise vbObjectError + 514, "FunctionWithHandler", "Not handled in this routine" End Select End Function Private Function FunctionWithOutHandler() As Long 'Force an error Err.Raise vbObjectError + 515, "FunctionWithOutHandler", "Not handled in this routine" FunctionWithOutHandler = 1 End Function NickHK "Jason Zischke" wrote in message ... Hi all, I was wondering if there was a way to do some sought of global On Error Command because all I need is for it to pop up with the same message and to go throughout all of my forms & modules and put on the On Error Command and with the Error Trapping in all of my proceedures? Jason |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Error when using Sum command | Excel Discussion (Misc queries) | |||
Pivot Table Error Message - "Command Text not set for command obje | Excel Discussion (Misc queries) | |||
Error with Goto command | Excel Programming | |||
Do loop error while using FindNext command | Excel Programming | |||
Why does the error pop up- can't enter command mode? | Excel Programming |