Error function
Returns the error message that corresponds to a given error number.
Syntax
Error [ (errornumber) ]
The optional errornumber argument can be any valid error number. If errornumber is a valid error number, but is not defined, Error returns the string "Application-defined or object-defined error."
If errornumber is not valid, an error occurs. If errornumber is omitted, the message corresponding to the most recent run-time error is returned. If no run-time error has occurred, or errornumber is 0, Error returns a zero-length string ("").
Remarks
Examine the property settings of the Err object to identify the most recent run-time error. The return value of the Error function corresponds to the Description property of the Err object.
Example
This example uses the Error function to print error messages that correspond to the specified error numbers.
Private Sub PrintError()
Dim ErrorNumber As Long, count As Long
count = 1: ErrorNumber = 1
On Error GoTo EOSb
Do While count < 100
Do While Error(ErrorNumber) = "Application-defined or object-defined error": ErrorNumber = ErrorNumber + 1: Loop
Debug.Print count & "-Error(" & ErrorNumber & "): " & Error(ErrorNumber)
ErrorNumber = ErrorNumber + 1
count = count + 1
Loop
EOSb: Debug.Print ErrorNumber
End Sub
See also
Support and feedback
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기