Spellcheck a single word in Excel function

WhiskerBiscuit picture WhiskerBiscuit · May 27, 2012 · Viewed 8.9k times · Source

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

Function SpellCheck(SomeWord As String)

SpellCheck = Application.CheckSpelling(SomeWord)

End Function

In fact, in the IDE I can verify that Application.CheckSpelling("hello") fails, though the Excel spellchecker does detect misspellings.

What I'm trying to do is get a T/F value for each word if it is spelled correctly.

Answer

Siddharth Rout picture Siddharth Rout · May 27, 2012

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