Spellcheck a single word in Excel function

前端 未结 5 411
不知归路
不知归路 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:02

    Like I mentioned in my comment it works.

    Option Explicit
    
    Sub Sample()
        MsgBox SpellCheck("hello") '<~~ Returns True
        MsgBox SpellCheck("daasd") '<~~ Returns False
    End Sub
    
    Function SpellCheck(SomeWord As String) As Boolean
        SpellCheck = Application.CheckSpelling(SomeWord)
    End Function
    

    Application.CheckSpelling will not correct or offer to correct a misspelled word, it only returns True or False

    I tested

    ?Application.CheckSpelling("hello")

    in immediate window and it returned True

    EDIT: Calling Application.CheckSpelling from UDF would always return False. Last time I checked, it was still a bug and there was no way around it. If there is a recent update on that then I am not aware of it. :)

    MORE EDIT

    Here is your function slightly modified which will work as a UDF as well :)

    Got the idea from this link

    Function SpellCheck(rng As Range) As Boolean
        Dim oxlAp As Object
        Set oxlAp = CreateObject("Excel.Application")
        SpellCheck = oxlAp.CheckSpelling(rng.Value)
        oxlAp.Quit
        Set oxlAp = Nothing
    End Function
    

提交回复
热议问题