On Error Resume Next is one of a few ways to do “Error handling in VBA” ( http://www.excelfox.com/forum/showth...GoRoT-N0Nula-1 )
On Error Resume Next at the start of your program will tell VBA to keep going even if it crashes or has problems many times.
It is like you go on a long journey in your car. But you decide to drive very fast and if you have lots of crashes and accidents you just keep going very fast and ignore all your accidents and crashes.
This can do damage and break things.
It does not just stop the error message. It does stop the error message , you are correct , … but also it does keep going even if things are broken or not working properly. This might do bad damage. You may not notice this damage until something else goes badly wrong. It may cause lots of confusing problems later.
On Error Resume Next at the start of your program is dangerous. You may be lucky one day and it will cause no problems. Or you may be unlucky and it will cause lots of problems and cause lots of damage.
Usually there is a better way to achieve what you want without Error Handling.
Some ways to use Error handling are not too bad.
For example:
This is very Bad
This is not so badCode:Sub BadErrorHandling() On Error Resume Next ' Error handling is ON Dim Nmbr As Long: Let Nmbr = 0 ' ' code '' code '' code '' code '' code '' code '' code '' code '' code ' Let Nmbr = 1 / Nmbr ' ' ' code '' code '' code '' code '' code '' code ' End Sub
The last macro is not so bad because you only use the error handling for a short piece of the code which you think may error.Code:Sub NotSoBadErrorHandling() Dim Nmbr As Long: Let Nmbr = 0 ' ' code '' code '' code '' code '' code '' code '' code '' code '' code ' On Error Resume Next ' Error handling is ON Let Nmbr = 1 / Nmbr On Error GoTo 0 ' Error handling is OFF ' ' ' code '' code '' code '' code '' code '' code ' End Sub
But it is still better to do it without error handling
Code:Sub AlternativeToErrorHandling() Dim Nmbr As Long: Let Nmbr = 0 ' ' code '' code '' code '' code '' code '' code '' code '' code '' code ' If Nmbr <> 0 Then Let Nmbr = 1 / Nmbr ' ' ' code '' code '' code '' code '' code '' code ' End Sub
Alan




Reply With Quote

Bookmarks