I have a function where the intention is to return either a string to signify that the function has completed and retrieved the required value or an error to indicate there has been an issue.
To see whether I could do this, I bashed together the following:
Private Function one()
Debug.Print TypeName(two(False))
End Function
Private Function two(b As Boolean) As Variant
Dim e As New ErrObject
If (b) Then
two = True
Else
two = e.number
End If
End Function
Now, this fails at two = e.number because you don't appear to be able to set an error number in this way - the syntax is incorrect.
I could use err.raise but then the intention is to pass the whole error object back as I can then have a custom number and fill in my own description etc...
How do you actually pass the err object back? Can you actually do it and is this the most effective way in achieving what I am setting out to do?
Thanks
Err?two = Err?Raisean error - you cannot directly create anErrobject cpearson.com/Excel/ErrorHandling.htm. YourErrObjectseems to be VB.NetErrObjectis absolutely VBA:Erris a function, a member of theVBA.Informationmodule, that returns anErrObject. An instance of theErrObjectclass cannot be created with theNewkeyword.