Spellcheck a single word in Excel function

前端 未结 5 410
不知归路
不知归路 2021-01-11 12:32

This little Excel VBA function always returns false, no what word is passed in.

Function SpellCheck(SomeWord As String)

SpellCheck = Application.CheckSpelli         


        
5条回答
  •  星月不相逢
    2021-01-11 13:09

    While the bug in using the Excel Application object still exists, a UDF that requires it for the Application.CheckSpelling method can benefit from Early Binding and a Static variable declaration.

    Function spellCheck(str As String) As Boolean
        Static xlApp As New Excel.Application
        spellCheck = xlApp.CheckSpelling(str)
    End Function
    

    The early binding speeds up the creation of the Excel.Application object. When used within Excel's VBA there is no need to use the CreateObject function as the reference library exists.

    The Static variable declaration continues to exist in its assigned state after the function has been exited and is not recast on subsequent uses of the UDF. This makes situations like using the UDF to fill down a long column or as the determination formula in a conditional formatting rule more efficient.

提交回复
热议问题