Hyperlink formatting lost after replacement in outlook

Not open for further replies.


Outlook version
Outlook 2007
Email Account
Exchange Server
I have written a code which replaces the text of certain format into a hyperlink. This code is invoked by a rule during an Incoming email.

Incoming email -> copy the email to word editor -> make necessary changes -> copy from word editor to outlook mail item(replaced hyperlinks gets lost in mail item, while newly added text reamins intact)

My code is here for your refernce..

Collapse | Copy Code

Sub IncomingHyperlink(MyMail As MailItem) Dim strID As String Dim Body As String Dim objMail As Outlook.MailItem Dim myObject As Object Dim myDoc As Word.Document Dim mySelection As Word.Selection strID = MyMail.EntryID Set objMail = Application.Session.GetItemFromID(strID) 'Creates word application Set objWord = CreateObject("Word.Application") objWord.Visible = True Set objDoc = objWord.Documents.Add() Set objSelection = objWord.Selection 'Copies contents of email into word document objSelection.TypeText "GOOD" & objMail.HTMLBody With objSelection.Find .ClearFormatting .Text = "ASA[0-9][0-9][0-9][0-9][a-z][a-z]" .Forward = True .Wrap = wdFindAsk .MatchWildcards = True End With objSelection.Find.Execute objSelection.Hyperlinks.Add Anchor:=objSelection.Range, _ Address:="http://www.code.com/" & objSelection.Text, _ TextToDisplay:=objSelection.Text 'Copies contents to email item from word document objMail.HTMLBody = objDoc.Range(0, objDoc.Range.End) objMail.Save Set objMail = Nothing End SubAlso, this code replaces only the first occurrence of the needed text and does not replace others.
Please help solve these problems. Thank you...
I have tried out different options and still not able to get it work.
Not open for further replies.