K
keeena
One of my workbooks features automation within Excel Objects; e.g. I
have added my own properties and methods to some Worksheet objects.
I'm noticing that raising errors from Excel Objects does not seem to
work as I intended. I'm using Excel 2003 and VBA. I searched the NGs
and couldn't find any information on raising errors w/in Excel object
modules.
' *Sample Code*
' Put this code w/in Sheet1 object
Private mRow As Long
Public Sub SetRow(ByVal Value As String)
On Error GoTo ErrProc
mRow = Application.WorksheetFunction.Match(Value, Me.Columns("A"),
0)
Exit Sub
ErrProc:
Err.Raise vbObjectError + 1001, ,"Release value could not be
matched in the table"
End Sub
' End Sheet1 code
' Put this code in Module1
Sub RunMe()
On Error GoTo ErrHandler
Sheet1.SetRow "ThisStringDoesNotExistInSheet1ColA"
MsgBox "Doing other stuff..."
ExitProc:
Exit Sub
ErrHandler:
MsgBox Err.Number & Err.Description
If Err.Number = vbObjectError + 1001 Then
Resume Next
Else
Resume ExitProc
End If
End Sub
' End Module1 code
' *End Sample Code*
I noticed that Err.Description changes based on the error number I
choose to use, which leads me to believe that there are additional
Error #'s defined which are unique to the MS Excel Objects (? or
something along those lines). I did try using larger error #'s as
well as removing vbObjectError...this didn't help.
I'd just like to know more details about why this is occurring and if
there is a way I could use err.raise to return my own errors..
Thanks,
-K
have added my own properties and methods to some Worksheet objects.
I'm noticing that raising errors from Excel Objects does not seem to
work as I intended. I'm using Excel 2003 and VBA. I searched the NGs
and couldn't find any information on raising errors w/in Excel object
modules.
' *Sample Code*
' Put this code w/in Sheet1 object
Private mRow As Long
Public Sub SetRow(ByVal Value As String)
On Error GoTo ErrProc
mRow = Application.WorksheetFunction.Match(Value, Me.Columns("A"),
0)
Exit Sub
ErrProc:
Err.Raise vbObjectError + 1001, ,"Release value could not be
matched in the table"
End Sub
' End Sheet1 code
' Put this code in Module1
Sub RunMe()
On Error GoTo ErrHandler
Sheet1.SetRow "ThisStringDoesNotExistInSheet1ColA"
MsgBox "Doing other stuff..."
ExitProc:
Exit Sub
ErrHandler:
MsgBox Err.Number & Err.Description
If Err.Number = vbObjectError + 1001 Then
Resume Next
Else
Resume ExitProc
End If
End Sub
' End Module1 code
' *End Sample Code*
I noticed that Err.Description changes based on the error number I
choose to use, which leads me to believe that there are additional
Error #'s defined which are unique to the MS Excel Objects (? or
something along those lines). I did try using larger error #'s as
well as removing vbObjectError...this didn't help.
I'd just like to know more details about why this is occurring and if
there is a way I could use err.raise to return my own errors..
Thanks,
-K