title: Find text and replace with hyperlink
body: <p>I am trying to replace text in the body with pattern ASA####@@ to ASA####@@(hyperlink)</p>
  
  <p>I have code which works if there is only one pattern in the body.</p>
  
  <p>But if I have many patterns like</p>
  
  <p>ASA3422df<br>
  ASA2389ds<br>
  ASA1265sa  </p>
  
  <p>the entire body gets replaced to </p>
  
  <p>ASAhuyi65 </p>
  
  <p>My code is here.</p>
  
  <pre class="lang-vb prettyprint-override"><code>Dim strID As String
  Dim Body As String
  Dim objMail As Outlook.MailItem
  Dim temp As String
  Dim RegExpReplace As String
  Dim RegX As Object
  strID = MyMail.EntryID
  
  Set objMail = Application.Session.GetItemFromID(strID)
  Body = objMail.HTMLBody
  Body = Body + "Test"
  objMail.HTMLBody = Body
  
  Set RegX = CreateObject("VBScript.RegExp")
  With RegX
  .Pattern = "ASA[0-9][0-9][0-9][0-9][a-z][a-z]"
  .Global = True
  .IgnoreCase = Not MatchCase
  End With
  'RegExpReplace = RegX.Replace(Body, "http://www.code.com/" + RegX.Pattern + "/ABCD")
  
  'if the replacement is longer than the search string, future .FirstIndexes will be off
  Offset = 0
  'Set matches = RegX.Execute(Body)
  
  For Each m In RegX.Execute(Body)
      RegExReplace = "&lt;a href=""http://www.code.com/" &amp; m.Value &amp; """&gt;" &amp; m.Value &amp; "&lt;/a&gt;"
  Next
  
  Set RegX = Nothing
  objMail.HTMLBody = RegExReplace
  objMail.Save
  Set objMail = Nothing
  End Sub
  </code></pre>