我有一个受保护的文档,我可以运行以下行,但无法实际对文本运行"拼写检查"并认为这是由于我的范围声明,有人可以指出出了什么问题吗?
例如:这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
击中每个范围。