UDF Error Handling is ignored. Not for everyone?

G

Guest

I have created a new function to try to recreate an example function
that mimics my intent:

Public Function HelloWorld(causeError As Boolean) As String


On Error GoTo ErrorHandler
If (causeError) Then
Err.Raise 1234
Else
HelloWorld = "Hello World"
End If


FunctionExit:
Exit Function


ErrorHandler:
Err.Clear
HelloWorld = "ERROR HAPPENED"
Resume FunctionExit


End Function

For me;
=HelloWorld(FALSE) returns "Hello World"
=HelloWorld(TRUE) returns #VALUE!

For someone else, they get;
=HelloWorld(FALSE) returns "Hello World"
=HelloWorld(TRUE) returns "ERROR HAPPENED"

What could be the problem? I am using Excel 2003, SP2
 
N

Niek Otten

Not very likely, but this could happen if your system has a language where FALSE is "FALSE" but TRUE is a different word. And of
course you could have misspelled TRUE....:)
 
G

Guest

Ok, I see your point. Just in case, I have simplified things even
further so that the error is not an argument-type issue.

Public Function HW() As String

On Error GoTo ErrorHandler
Err.Raise 1234


FunctionExit:
Exit Function

ErrorHandler:
Err.Clear
HW = "ERROR HAPPENED"
Resume FunctionExit

End Function

I still get:
=HW() returns: #VALUE!
 
D

Dave Peterson

maybe (with the the VBE):

Tools|options|General tab
check break on unhandled errors
(I'm betting you have break on all errors)

I could mimic your results that way.
 
G

Guest

Dave,

You ARE my HERO! A simple little thing like that.... It would have been
nice if it was going to "Break on that darn error" to open the debugger
in a "break state"! Anyway, thanks a ton. I've been digging for that
answer for two days.

Thanks!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top