WorksheetFunction 物件 (Excel)WorksheetFunction object (Excel)

做為可從 Visual Basic 中呼叫之 Microsoft Excel 工作表函數的容器。Used as a container for Microsoft Excel worksheet functions that can be called from Visual Basic.

範例Example

使用 Application 物件的 WorksheetFunction 屬性可傳回 WorksheetFunction 物件。Use the WorksheetFunction property of the Application object to return the WorksheetFunction object.

下列範例會顯示將 Min 工作表函數套用到 A1:C10 範圍之後的結果。The following example displays the result of applying the Min worksheet function to the range A1:C10.

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

此範例會使用 CountA 工作表函數來判斷欄 A 中有多少儲存格內含有值。This example uses the CountA worksheet function to determine how many cells in column A contain a value. 在此範例中,欄 A 中的值應為文字。For this example, the values in column A should be text. 此範例會針對欄 A 中的各個值進行拼字檢查,如果值的拼字錯誤,會將「錯誤」兩個字插入欄 B。否則,會將「確定」這兩個字插入欄 B。This example does a spell check on each value in column A, and if the value is spelled incorrectly, inserts the text "Wrong" into column B; otherwise, it inserts the text "OK" into column 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

方法Methods

屬性Properties

另請參閱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.