title: Find replace MS Word with Macro
body: <p>I have written a macro that replaces a file path with the current files location in Word 2016.</p>
  
  <pre><code>Dim i As Long, j As Long
  Dim s As String
  s = ActiveDocument.Path
  Dim sa As String
  sa = Replace(s + "\test1.xlxs", "\", "\\")
  
  For Each myStoryRange In ActiveDocument.StoryRanges
      With myStoryRange.Find
          .Text = "C:*test1.xlsx"
          .Replacement.Text = sa
          .MatchWildcards = True
          .Wrap = wdFindContinue
          .Execute Replace:=wdReplaceAll
      End With
  Next myStoryRange
  
  
  End Sub
  </code></pre>
  
  <p>This shows the error "the replacement text contains a group number that is out of range"</p>
  
  <p>The 'sa' variable has the correct string in it, i checked this at run time.
  Also when i replace </p>
  
  <pre><code>.Replacement.Text = sa
  </code></pre>
  
  <p>with</p>
  
  <pre><code>.Replacement.Text = "bla"
  </code></pre>
  
  <p>It works.
  At run time an example of 'sa' would be "C:\\Users\\Me\\Documents\\test1.xlsx"</p>
  
  <p>Does anyone have any suggestions what might be the problem?</p>