在Excel函数中拼写检查单个单词 [英] Spellcheck a single word in Excel function
问题描述
功能SpellCheck(SomeWord As String)这个小的Excel VBA函数总是返回false,
SpellCheck = Application.CheckSpelling(SomeWord)
结束功能
事实上,在IDE中,我可以验证Application.CheckSpelling(hello)是否失败,尽管Excel拼写检查器会检测到拼写错误。
如果拼写正确,则尝试做的是获取每个单词的T / F值。
像我在我的评论是有用的。
Option Explicit
子样本()
MsgBox SpellCheck hello)'< ~~返回True
MsgBox SpellCheck(daasd)'< ~~返回False
End Sub
函数SpellCheck(SomeWord As String) As Boolean
SpellCheck = Application.CheckSpelling(SomeWord)
结束函数
Application.CheckSpelli ng
不会更正或提供纠正拼写错误的单词,它只返回 True
或 False
我测试过
?Application.CheckSpelling(hello)
在立即窗口中,它返回 True
编辑:从UDF调用 Application.CheckSpelling
将始终返回 False
。上次我检查了,它还是一个bug,没有办法。如果有最新的更新,那么我不知道。 :)
更多编辑
这是您的功能稍作修改,将会工作作为UDF:)
从这个链接
功能SpellCheck(rng As Range)As Boolean
Dim oxlAp As Object
设置oxlAp = CreateObject(Excel.Application)
SpellCheck = oxlAp.CheckSpelling(rng.Value)
oxlAp.Quit
设置oxlAp = Nothing
结束函数
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.
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
这篇关于在Excel函数中拼写检查单个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!