title: Loop whole word 2007 document using vba
body: <p>I am working on a user form for finding specific phrases and commenting them according to certain criteria. I have trouble adding comments for all found phrases in the document. It only changes the first found phrase although it selects all occurrences of the phrase. How can i modify this code for the whole content?</p>
  
  <p>Here is my code:</p>
  
  <pre><code> If Criteria2 &lt;&gt; "" Then
          Selection.Find.ClearFormatting
          With Selection.Find
              .Text = Criteria2
              .Replacement.Text = ""
              .Forward = True
              .Wrap = wdFindAsk
              .Format = False
              .MatchCase = False
              .MatchWholeWord = False
              .MatchWildcards = False
              .MatchSoundsLike = False
              .MatchAllWordForms = False
              .Execute
          End With
         On Error Resume Next
          With Selection
              .Comments.Add Range:=Selection.Range, Text:="SPE 2"
          End With
  End If
  </code></pre>
  
  <hr>
  
  <p>Ok Here is the new code and it is not working as expected:</p>
  
  <pre><code>Selection.Find.ClearFormatting
          With Selection.Find
             .Text = CritArray(i)
             .Replacement.Text = ""
             .Forward = True
             .Wrap = wdFindContinue
             .Format = False
             .MatchCase = False
             .MatchWholeWord = False
             .MatchWildcards = False
             .MatchSoundsLike = False
             .MatchAllWordForms = False
             Do
                 .Execute
                 If Not .Found Then
                  Exit Do
                 ElseIf .Found Then
                  FoundCount = FoundCount + 1
                  Selection.Comments.Add Range:=Selection.Range, Text:=MessArray(i) &amp; CritArray(i) &amp; "' - found for the" &amp; Str(FoundCount) &amp; ". time"
                 End If
              Loop 
          End With
  </code></pre>
  
  <p>What I get when using this as input:</p>
  
  <pre><code>Testrow1
  Testrow2
  </code></pre>
  
  <p>is the following:</p>
  
  <pre><code>Testrow1 ....................................'Testrow1' - found for the 1. time
  Testrow2 ....................................'Testrow2' - found for the 2. time
                                               'Testrow2' - found for the 1. time
  </code></pre>
  
  <p>I cannot understand why this is happening since the do .. loop should exit if nothing is found. Is it possible that .Wrap = wdFindContinue is the problem? There are three possibilities here: </p>
  
  <ul>
  <li>wdFindAsk ... asks at the end of document to search again at the beginning (don't want this)</li>
  <li>wdFindContinue ... searches without asking</li>
  <li>wdFindStop ... stops when it first finds the search phrase (don't want this)</li>
  </ul>
  
  <p>Anybody got a clue?</p>