Error Function
Collapse the table of content
Expand the table of content

Error Function

Office 2013 and later

Contribute to this content

Use GitHub to suggest and submit changes. See our guidelines for contributing to VBA documentation.

Returns the error message that corresponds to a given error number.



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 ("").


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.

This example uses the Error function to print error messages that correspond to the specified error numbers.

Dim ErrorNumber
For ErrorNumber = 61 To 64    ' Loop through values 61 - 64.
    Debug.Print Error(ErrorNumber)    ' Print error to Immediate window.
Next ErrorNumber

© 2016 Microsoft