WorksheetFunction 物件 (Excel)

做為可從 Visual Basic 中呼叫之 Microsoft Excel 工作表函數的容器。

範例

使用 Application 物件的 WorksheetFunction 屬性可傳回 WorksheetFunction 物件。

下列範例會顯示將 Min 工作表函數套用到 A1:C10 範圍之後的結果。

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

此範例會使用 CountA 工作表函數來判斷欄 A 中有多少儲存格內含有值。 在此範例中,欄 A 中的值應為文字。 此範例會針對欄 A 中的各個值進行拼字檢查,如果值的拼字錯誤,會將「錯誤」兩個字插入欄 B。否則,會將「確定」這兩個字插入欄 B。

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 支援與意見反應