title: Macro to find multiple strings and insert text (specific to each string) at the end of each occurrence
body: <h3>The scenario:</h3>
  
  <p>Word documents that contain a selection of sentences (strings). There might be up to 30 possible strings (which vary from 5 to 20 words in length). The document will contain only a selection of these strings.</p>
  
  <h3>Aim:</h3>
  
  <p>Macro that searches through the document, <strong>finds each occurrence</strong> of a particular string and <strong>inserts a specific text code</strong> (such as " (ACWD2553)") <strong>after</strong> each occurrence. This is repeated for all the other strings in the set, with each different string having it's own distinct code. Some strings won't be in the document. The strings  can be located in document body and table cells.
  The macro would then be applied to other documents which would have different selections of the strings.</p>
  
  <p>I have tried for many days using selection.find, content.find, target.list, insertafter and so on but only with one case and still ran into numerous problems (e.g. only inserting in one instance, or code repeatedly inserting until Word freezes).</p>
  
  <h3>Bonus feature ###</h3>
  
  <p>Be able to choose which set of strings which will be searched for (there are potentially up to 60 sets) and their corresponding codes. Each document would only have strings from one set.</p>
  
  <p>An idea I had was for the strings to be listed in a column (in Excel?) and the matching codes in the a second column. The macro would then search the document for each string in the list (stopping at the end of the list since the number of strings varies between sets) finds the matching code in the cell in the next column and then inserts the code for each occurrence of the string in the word doc. When a different set is required, the Excel file could be swapped with the file containing the relevant set of stings, but with the same file name. Or all sets in the one Excel file on different worksheets and tab name entered in Word (userform?) which forces search of relevant set. This file would be located on a network drive.</p>
  
  <p>Not sure if this is bigger then Ben Hur, last bit would be nice, but I can also manually enter the strings in the raw code from a template code.</p>
  
  <p>Edited this post to include my poor attempt at the code. See my comment below. I just realised that I could add code to this pane. Tried a variety of iterations of the one below, none of which worked well and which does not approach what I require. I  know there are obvious errors, as I said below I have played around with the code and made it worse in the process by mixing bits and pieces together.</p>
  
  <pre><code>Sub Codes()
  
  Dim range As range
  Dim i As Long
  Dim TargetList
  
  TargetList = Array("This is sentence 1", "This is string 2 which could be twenty words in length", "This is string three, there could be thirty more strings to search") ' put list of terms to find here
  
  For i = 0 To UBound(TargetList)
  
  Set range = ActiveDocument.range
  
  With range.Find
  .Text = TargetList(i)
  .Format = False
  .MatchCase = False
  .MatchWholeWord = False
  .MatchWildcards = False
  .MatchSoundsLike = False
  .MatchAllWordForms = False
  
  Do While .Execute(Forward:=True) = True
  range.Find.Execute
  range.InsertAfter Text:=" (ACWD1234)"
  
  Loop
  
  End With
  Next
  
  End Sub
  </code></pre>