Thread: Error Trapping
View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Error Trapping

There is no programmatic way to do this. That said, in general, you
don't want to use "Break on Unhandled Errors". It is much better to
use "Break In Class Module". The reason is this: Suppose you have some
class module named Class1 and it has code that goes awry and throws an
error. E.g,

' In Module1
Sub AAA()
Dim C As Class1
Set C = New Class1
C.ABC
End Sub

' In Class1
Public Sub ABC()
Debug.Print 1/0 ' Force an error
End Sub

When you run AAA which creates the instance of Class1 and then calls
the ABC method, a Div/0 error occurs. If you have error handling set
to "Break On Unhandled Errors", the debugger will take you to
procedure AAA to the line C.ABC. That is rather confusing because
there is obviously nothing wrong with line of code "C.ABC". If you use
"Break In Class Module", the debugger will take you into Class1 to the
line that actually threw the 1/0 error. It is much more informative.
And if you don't know why the "wrong" line is highlighted by the
debugger, you can spend quite a bit of time trying to figure it out.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Sat, 20 Jun 2009 08:21:59 -0400, "AG"
wrote:

Can VBA Project Error Trapping be set via code in any version of Excel from
2000 up?
If so, how?

I would like to insure that when my workbook opens, it is set to Break on
Unhandled Errors and not Break on All Errors.

Thanks,