簡體   English   中英

字段范圍的拼寫檢查 - Word VBA

[英]Checkspelling on Field Range - Word VBA

我有一個受保護的文檔,我可以運行以下行,但無法對文本實際運行“拼寫檢查”,並認為這是由於我的范圍聲明造成的,有人能指出什么問題嗎?

例如:這將正確返回TRUE/FALSE If CheckSpelling(theFields.Result.Text) = False Then但我不能運行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命中每個范圍。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM