2012-07-26 27 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