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
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.