View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Vasant Nanavati Vasant Nanavati is offline
external usenet poster
 
Posts: 1,080
Default Returning custom errors from UDFs

Try:

Foo = CInt(CVErr(lngFuncReturn))

--

Vasant


"Dave" wrote in message
oups.com...
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