Excel VBA Macro Programming
Why would you want to generate your own errors? After all, you want to achieve error-free code. Sometimes it is useful when you are testing your own applications or when you want to treat a particular condition as being equivalent to a runtime error.
You can generate an error in your code with the Error statement:
Sub Test_Error() Error 71 End Sub
This simulates the ‚“Drive not ready ‚½ error. You could also use Err.Raise(71) to do this. In addition, you can regenerate the current error by using the following:
Error Err