如何将我的代码放在do while循环中?

时间:2012-07-26 05:42:20

标签: vba ms-word word-vba

我想用单词检查整个页面的这个条件。

If Options.CheckGrammarWithSpelling = True Then
    Selection.Comments.Add Range:=Selection.Range
    Selection.TypeText Text:="WRONG!!!"
    'ActiveDocument.CheckGrammar
Else
    'ActiveDocument.CheckSpelling
    'Selection.Comments.Add Range:=Selection.Range
End If

1 个答案:

答案 0 :(得分:1)

您不需要Do While循环。这是你在尝试什么?

Sub DoSpellCheckAndComment()
    Dim oWord As Range
    Dim StoryRange As Range

    For Each StoryRange In ActiveDocument.StoryRanges
        Application.CheckSpelling Word:=StoryRange
        For Each oWord In StoryRange.Words
            If Not Application.CheckSpelling(Word:=oWord.Text) Then
                oWord.Select
                oWord.Comments.Add Range:=Selection.Range, Text:="WRONG!!!"
            End If
        Next oWord
    Next StoryRange
End Sub