ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   General question re Error Handling (https://www.excelbanter.com/excel-programming/437230-general-question-re-error-handling.html)

terry w

General question re Error Handling
 
hello experts

This is just a general question for my own education. I've dabbled in a
fair amount of Access VBA in the past, but have just started learning about
Excel VBA. In Access, we would use Error Handling in almost every sub, but
In Excel, error Handling seems to be the exception rather than the rule. I
can't even find much about it in the Excel VBA help, and there are relatively
few references to it in this forum. What gives?

Just Curious
Terry W.

Robert Flanagan

General question re Error Handling
 
Terry, I use it all the time. My favorite approach is:

Public Const bDebug as boolean = true or false (depending on need)

Sub Main_Routine_With_Error_Trap()
if not bdebug then on error goto etrap
Main_Procedure
exit sub
etrap:
msgbox "Woops " & err.desription
End Sub

The above, with a better message obviously, traps all errors except those
in procedures in user forms. I thus tend to not run any elaborate user form
code other than input validation.

If I'm debugging code, I set bDebug to True. When I'm done, I set to False.
And, I put a If statement in the auto_close to warn me if bDebug is true.

Some use of On Error Resume Next to avoid errors and then testing the result
to see what actually happened. For example

Dim wB as workbook
set wB = Nothing
On error resume next
set wB = workbooks("My workbook.xls")
on error goto 0
if wb is nothing then msgbox "My workbook.xls is not open"

Robert Flanagan
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel



"terry w" wrote in message
...
hello experts

This is just a general question for my own education. I've dabbled in a
fair amount of Access VBA in the past, but have just started learning
about
Excel VBA. In Access, we would use Error Handling in almost every sub,
but
In Excel, error Handling seems to be the exception rather than the rule.
I
can't even find much about it in the Excel VBA help, and there are
relatively
few references to it in this forum. What gives?

Just Curious
Terry W.




Dave Peterson

General question re Error Handling
 
Chip Pearson shares a lot of notes:
http://www.cpearson.com/excel/ErrorHandling.htm



terry w wrote:

hello experts

This is just a general question for my own education. I've dabbled in a
fair amount of Access VBA in the past, but have just started learning about
Excel VBA. In Access, we would use Error Handling in almost every sub, but
In Excel, error Handling seems to be the exception rather than the rule. I
can't even find much about it in the Excel VBA help, and there are relatively
few references to it in this forum. What gives?

Just Curious
Terry W.


--

Dave Peterson

terry w

General question re Error Handling
 
Thanks Robert and Dave. This was quite helpful.
Terry W.


"Dave Peterson" wrote:

Chip Pearson shares a lot of notes:
http://www.cpearson.com/excel/ErrorHandling.htm



terry w wrote:

hello experts

This is just a general question for my own education. I've dabbled in a
fair amount of Access VBA in the past, but have just started learning about
Excel VBA. In Access, we would use Error Handling in almost every sub, but
In Excel, error Handling seems to be the exception rather than the rule. I
can't even find much about it in the Excel VBA help, and there are relatively
few references to it in this forum. What gives?

Just Curious
Terry W.


--

Dave Peterson
.



All times are GMT +1. The time now is 01:31 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com