Find and replace text with hyperlinks
Hi ,
I am facing a problem now. I want to search for ASA1234yy in the body of a text and replace it with the hyperlink ASA1234yy
Can you help me to get started. I have tried using Replace function, but it Replaces only text. I want the text to be replaced with a hyperlink.
Please help me.
Thanks
Re: Find and replace text with hyperlinks
One more criteria is that the body may contain many ids of this format, like ASA1234yy, ASA3456jj etc and replace it with their respective hyperlinks.
Thanks.
Re: Find and replace text with hyperlinks
OutLook
What code do you have so far?
I have no direct experience doing what you describe,
but it sounds like you need to do more than just Replace.
You probably also need to add Tags like "(url)" and "(/url)",
or something along those lines.
Note that you would actually use "[" instead of "(", but to prevent
the editor here from thinking it was a link, I had to use "(" for
illustrative purposes.
Spoo
Re: Find and replace text with hyperlinks
I am quoting for his reply. I did not do that for this post. So deleting the content as unable to delete the reply.
Apologies for any inconvenience caused.
Re: Find and replace text with hyperlinks
Quote:
Originally Posted by
Spoo
OutLook
What code do you have so far?
I have no direct experience doing what you describe,
but it sounds like you need to do more than just Replace.
You probably also need to add Tags like "(url)" and "(/url)",
or something along those lines.
Note that you would actually use "[" instead of "(", but to prevent
the editor here from thinking it was a link, I had to use "(" for
illustrative purposes.
Spoo
Sub ConvertToHyperlink(MyMail As MailItem)
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.Body
Body = Body + "Test"
objMail.Body = 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.vba.com" + RegX.Pattern + "/ABCD")
Set RegX = Nothing
objMail.Body = RegExpReplace
objMail.Save
Set objMail = Nothing
End Sub
This is the code, I have so far.