2012-07-26 84 views
-1

我想在word中检查整个页面的这个条件。如何把我的代码放在do while循环中?

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 
+0

错误的代码格式,我看不到'do while'构造。你应该告诉更多,并提供更多的代码,并*格式*正确。你的问题不清楚。 – 2012-07-26 05:45:51

+0

可以在这段代码中加入do ... – user1553562 2012-07-26 05:58:07

+0

你试过了什么?你知道VBA中'do while'循环的语法吗?阅读更多关于他们!你的程序试图做什么? – 2012-07-26 06:01:35

回答

1

您不需要Do While Loop。这是你正在尝试的吗?

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 
+0

Thnx sidd ...它的工作 – user1553562 2012-07-26 06:37:50