Joe Marlow


Hello All,

I'm receiving the error message in subject in the following code:

Public Sub Err(ErrorID As Long, _
Optional AddInfo As String = "", _
Optional Source As String = "", _
Optional
Log As Boolean = True)

If Log = True Then Me.Log MsgTypeError, ErrorID, AddInfo, Source
MsgBox Me.GetErrorDescription(ErrorID), vbCritical + vbOKOnly, "FTCM Error"
End <= this is where the error occurs
End Sub


  • VBA.Err object is clean
  • the code lies in worksheet in Excel 2002 named "Log"
  • VBA.Err.Raise(Number:=513, Source:="Anything", Description:="Whatever") also raises the same error (not "Whatever" as I'd expect)
  • I know I have overriden names "Err" and "Log", but renaming does not solve anything

Edit 2007-10-29 17:24:
If I remove the "End" statement and place it into calling procedure after the Log.Err call, everything works as expected.


Does anyone have an idea, why this happens
Thanks in advance.



Re: Application-defined or object-defined error

Luiz Cláudio - MVP


Hi Joe,

End kills all the VBA variables and the object variables, including Application level events. It can cause some problems, especially if you have add-ins loaded, so it's not a good practice to use it.

If you use Application.Quit, do you have the same error message







Re: Application-defined or object-defined error

Joe Marlow

Hello Luiz,

it seem that Application.Quit actualy quits the whole Excel, this is not my intention, I just need to throw an exception (or just a message box) and stop the processing of VBA "macro". Anyway, thank you for your answer.





Re: Application-defined or object-defined error

Luiz Cláudio - MVP

Hi Joe,

to throw an exception, you can use Err.Raise method. In the caller procedure, you can use Exit Sub to stop the processing.