IsError 函数IsError function

返回一个 Boolean 值,指示表达式是否为错误值。Returns a Boolean value indicating whether an expression is an error value.

语法Syntax

IsError(表达式)IsError(expression)

必需的_expression_ 参数可以是任何有效的表达式。The required expression argument can be any valid expression.

备注Remarks

错误值是通过使用**CVErr** 函数将实数转换为错误值来创建的。Error values are created by converting real numbers to error values by using the CVErr function. IsError 函数用于确定数值表达式是否表示错误。The IsError function is used to determine if a numeric expression represents an error. 如果 expression 参数指示错误,则 IsError 返回 True;否则,返回 FalseIsError returns True if the expression argument indicates an error; otherwise, it returns False.

示例Example

此示例使用IsError函数检查数值表达式是否为错误值。This example uses the IsError function to check if a numeric expression is an error value. 使用CVErr函数可从用户定义的函数返回错误变量The CVErr function is used to return an Error Variant from a user-defined function. 假定这UserFunction是一个返回错误值的用户定义的函数过程;例如, 使用语句UserFunction = CVErr(32767)分配的返回值, 其中32767是用户定义的数字。Assume that UserFunction is a user-defined function procedure that returns an error value; for example, a return value assigned with the statement UserFunction = CVErr(32767), where 32767 is a user-defined number.

Dim ReturnVal, MyCheck
ReturnVal = UserFunction()
MyCheck = IsError(ReturnVal)    ' Returns True.

另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.