Implications of Error Trapping


When you use an On Error statement in your code, that error trap remains throughout the procedure unless it is disabled. As you just saw, you can set up a routine to check whether the A: drive has a disk in it and take action accordingly . However, it is important to turn this off once the possibility of the error has taken place. If you do not do this, then all subsequent errors within that procedure will use the same error-handling routine. This gives extremely confusing results to the user as the error message is likely to be totally meaningless in relation to the error generated. A subsequent error could relate to division by zero, but the error message will come up saying ‚“Drive A not ready. ‚½

If On Error Resume Next has been used and not switched off, all sorts of errors could be taking place without the user being aware of them. You disable the error-trapping routine as follows :

 On Error Resume Next 
On Error GoTo 0

The On Error Resume Next statement that you saw previously ignores all errors. The On Error GoTo 0 cancels any error handling and allows all errors to be displayed as they normally would. This cancels out the On Error Resume Next and puts everything back to normal error handling.




Excel VBA Macro Programming
Excel VBA Macro Programming
ISBN: 0072231440
EAN: 2147483647
Year: 2004
Pages: 141

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net