title: Loop until search term is not found
body: <p>I've recorded a macro to, find a specific search term "INCLUDETEXT" in a large document, highlight the text associated with that search term, convert the highlighted text to a field code, and then update the new field code.</p>
  
  <p>I need to loop the macro until the "INCLUDETEXT" term is not found. </p>
  
  <p>I've tried to repeat the code 50 times, but ended up with odd nested field codes on the last instance of the "INCLUDETEXT" term.</p>
  
  <pre><code>Sub InsertFields()
  '
  ' InsertFields Macro
  ' Inserts field codes associated with an "INCLUDETEXT" link.
  '
      Selection.Find.ClearFormatting
      With Selection.Find
          .Text = "INCLUDETEXT"
          .Replacement.Text = ""
          .Forward = True
          .Wrap = wdFindContinue
          .Format = False
          .MatchCase = False
          .MatchWholeWord = False
          .MatchWildcards = False
          .MatchSoundsLike = False
          .MatchAllWordForms = False
      End With
      Selection.Find.Execute
      Selection.MoveLeft Unit:=wdCharacter, Count:=1
      Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
      Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
      Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
          PreserveFormatting:=False
      Selection.Fields.Update
  End Sub
  </code></pre>
  
  <p>The macro works on each single instance of the search term. I would like to find and update all "INCLUDETEXT" terms.</p>
  
  <p>I have looked at <a href="https://stackoverflow.com/questions/13465709/repeating-microsoft-word-vba-until-no-search-results-found">Repeating Microsoft Word VBA until no search results found</a>, but could not figure out how to adapt my macro to fit.</p>
  
  <p>My failed attempt at a "Do If" loop. I believe the specific error was an "End If" without an "If": </p>
  
  <pre><code>Sub InsertFields()
  '
  ' InsertFields Macro
  ' Inserts all fields associated with an "INCLUDETEXT" link.
  ' Selection.Find.ClearFormatting
      With Selection.Find
          .Text = "INCLUDETEXT"
          .Replacement.Text = ""
          .Forward = True
          .Wrap = wdFindContinue
          .Format = False
          .MatchCase = False
          .MatchWholeWord = False
          .MatchWildcards = False
          .MatchSoundsLike = False
          .MatchAllWordForms = False
      End With
      Do While Selection.Find.Found = True
      Selection.Find.Execute
      If Selection.Find.Found Then
      Selection.MoveLeft Unit:=wdCharacter, Count:=1
      Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
      Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
      Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
          PreserveFormatting:=False
      Selection.Fields.Update
      End If
      Loop
  End Sub
  </code></pre>