View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Dave[_57_] Dave[_57_] is offline
external usenet poster
 
Posts: 4
Default Returning custom errors from UDFs

I'm trying to return a custom error to Excel from my UDF. The calling
cell always displays #Value! when an error occurs. The Error.Type is 3,
corresponding to #Value!. Why don't I get my custom error number back?

Dave



Public Function Foo(intTest as Integer) As Variant

Dim lngFuncReturn As Long

On Error GoTo Foo_Error

'...Get the description
lngFuncReturn = MyFoo(intTest)
If (lngFuncReturn < STATUS_SUCCESS) Then

'...Return a custom error number
Foo = CVErr(lngFuncReturn)

Else

'...Make the function value the returned value:
Foo = lngFuncReturn

End If

Foo_Resume:
Exit Function

Foo_Error:

Foo = CVErr(xlErrNA)
Resume Foo_Resume

End Function