Resume Statement
The Resume statement can be used to resume execution after a run-time error occurs.
You can only use this statement inside an error handling routine.
Every time this statement is executed the Err Object is automatically reset.
Resume
ErrorHandler:
Resume
End Sub
This will move the execution back to the statement that caused the error.
If the error has not been resolved, the same error will be raised again which will create an infinite loop.
Resume Next
ErrorHandler:
Resume Next
End Sub
This will move the execution to the line after the statement that caused the error.
If the error occurred in the same procedure as the error handler, execution resumes with the statement immediately following the statement that caused the error.
If the error occurred in a called procedure, execution resumes with the statement immediately following the statement that last called out of the procedure containing the error-handling routine (or the On Error Resume Next statement).
Resume LineLabel
LineLabel:
ErrorHandler:
Resume LineLabel
End Sub
This will move execution to the corresponding line label.
The line argument is a line label or line number and must be in the same procedure as the error handler.
Nested Subroutines
If the error occurred in a called procedure, execution resumes at the statement that last called out of the procedure containing the error-handling routine.
Sub MySubroutine()
On Error Resume Next
Call MySub2 'the run-time error is ignored
End Sub
Sub MySub2()
Charts("Chart 1").Activate 'this generates a runtime error
End Sub
Resume without error
If it is used outside of an error handling routine a runtime error 20 "Resume without error" error will occur.
SS
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext