WorksheetFunction 对象 (Excel)

用作可从 Visual Basic 中调用的 Microsoft Excel 工作表函数的容器。

示例

使用 Application 对象的 WorksheetFunction 属性返回 WorksheetFunction 对象。

以下示例对单元格区域 A1:C10 应用 Min 工作表函数,并显示结果。

Set myRange = Worksheets("Sheet1").Range("A1:C10") 
answer = Application.WorksheetFunction.Min(myRange) 
MsgBox answer

本示例使用 CountA 工作表函数确定列 A 中包含某个值的单元格数量。 在本示例中,列 A 中的值为文本。 在本示例中,将对列 A 中的每个值执行拼写检查,如果值拼写不正确,则会在列 B 中插入文本“Wrong”;否则,将在列 B 中插入“OK”。

Sub StartSpelling()
   'Set up your variables
   Dim iRow As Integer
   
   'And define your error handling routine.
   On Error GoTo ERRORHANDLER
   
   'Go through all the cells in column A, and perform a spellcheck on the value.
   'If the value is spelled incorrectly, write "Wrong" in column B; otherwise, write "OK".
   For iRow = 1 To WorksheetFunction.CountA(Columns(1))
      If Application.CheckSpelling( _
         Cells(iRow, 1).Value, , True) = False Then
         Cells(iRow, 2).Value = "Wrong"
      Else
         Cells(iRow, 2).Value = "OK"
      End If
   Next iRow
   Exit Sub

    'Error handling routine.
ERRORHANDLER:
    MsgBox "The spell check feature is not installed!"
    
End Sub

方法

属性

另请参阅

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。