Errors![]() |
表示区域的电子表格错误。
使用 Errors 对象的 Item 属性可返回一个 Error 对象。
返回一个 Error 对象之后,可用 Value 属性,并在 Errors 属性的协助下检查某个特定错误检查选项是否可用。
下例中,在引用空单元格的单元格 A1 中创建一个公式,然后使用 Item(index) 显示描述状态的消息,其中,index 用于识别错误类型。
Sub CheckEmptyCells()
Dim rngFormula As Range
Set rngFormula = Application.Range("A1")
' Place a formula referencing empty cells.
Range("A1").Formula = "=A2+A3"
Application.ErrorCheckingOptions.EmptyCellReferences = True
' Perform check to see if EmptyCellReferences check is on.
If rngFormula.Errors.Item(xlEmptyCellReferences).Value = True Then
MsgBox "The empty cell references error checking feature is enabled."
Else
MsgBox "The empty cell references error checking feature is not on."
End If
End Sub
注意:不要将 Error 对象与 Visual Basic 的错误处理功能混淆。