Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default On Error Goto 0

It is most typically used in a block of code that you know may error, but
don't want a code failure if it does. To stop this, you put code to ignore
the error

On Error Resume Next

then the code that might fail, and then to get back to the status quo,
disable the error handling with

On Error Goto 0

As an example, if you want to test whether a worksheet exists, you could set
a worksheet variable to that worksheet. If it doesn't exist, this error
handling will stop a failure, and it can then be tested

On Error Resume Next
Set sh = Worksheets("somename")
On Error Goto 0
If sh Is Nothing Then
Msgbox "Sheet does not exist"
End If


Here is a more interesting example. At first sight you might think it would
loop in the error handler in the child routine, or after the first error we
would get no more error handling. In fact, it is neither. Try it and see

Sub DemoErrors()

On Error GoTo err_handler_1

Call DemoChild

err_handler_1:
MsgBox "Error handled in parent routine"
End Sub

Sub DemoChild()
Dim some_var

On Error GoTo err_handler_2

'force an error
some_var = 1 / 0
MsgBox "this shouldn't happen"
Exit Sub

err_handler_2:
MsgBox "We got an error in child routine"
'disable the current error handler
On Error GoTo 0

'now force another error
some_var = 1 / 0
End Sub



--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Perico" wrote in message
...
What does this do that having no Error catcher would not do? How is this
used? In testing, it simply takes you to the error; but wouldn't having
no
"On Error" expresion do the same thing? Or, is this used when you want to
trap an error in a specific part of your code?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error Handling - On Error GoTo doesn't trap error successfully David Excel Programming 9 February 16th 06 05:59 PM
on error goto Gixxer_J_97[_2_] Excel Programming 2 March 16th 05 08:49 PM
On Error Goto doesn't goto Paul Excel Programming 1 October 15th 04 03:51 PM
On Error Goto doesn't goto Paul Excel Programming 0 October 15th 04 03:05 PM
On Error GoTo StanJ[_2_] Excel Programming 1 July 31st 04 06:15 PM


All times are GMT +1. The time now is 11:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"