字段范围的拼写检查 - 单词 VBA



我有一个受保护的文档,我可以运行以下行,但无法实际对文本运行"拼写检查"并认为这是由于我的范围声明,有人可以指出出了什么问题吗?

例如:这If CheckSpelling(theFields.Result.Text) = False Then正确返回TRUE/FALSE但我无法运行theFields.CheckSpelling

我尝试过的:

Sub SpellCheckDoc()
Dim lockedFields As Long
Dim unlockedFields As New Collection
For Each theFields In ActiveDocument.Fields
If theFields.Locked = False Then
unlockedFields.Add theFields
End If
Next theFields
'Word
Dim objWord As Object
Set objWord = GetObject(, "Word.Application")
For Each theFields In unlockedFields
If CheckSpelling(theFields.Result.Text) = False Then
objWord.theFields.CheckSpelling
ActiveDocument.Range(theFields).CheckSpelling
End If
Next theFields
End Sub

你不需要

Dim objWord as Object
Set objWord = GetObject(, "Word.Application")

因为你是在 Word 中写的。

您想设置Options.SuggestSpellingCorrections = True,然后用theFields.Result.CheckSpelling击中每个范围。

最新更新