Checkspelling on Field Range - Word VBA

十年热恋 提交于 2020-02-06 08:47:30

问题


I have a protected document which I am able to run the following line, but unable to actually run "spellcheck" on the text and think it's due to my range declaration, can somebody point out whats wrong?

Eg: This returns TRUE/FALSE correctly If CheckSpelling(theFields.Result.Text) = False Then but I can't then run theFields.CheckSpelling

What I have tried:

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

回答1:


You don't need the

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

since you're writing this in Word.

You want to set Options.SuggestSpellingCorrections = True and then hit each range with a theFields.Result.CheckSpelling.



来源:https://stackoverflow.com/questions/59905099/checkspelling-on-field-range-word-vba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!