|
-
Jun 18th, 2011, 01:35 PM
#1
Thread Starter
New Member
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
-
Jun 18th, 2011, 01:37 PM
#2
Thread Starter
New Member
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.
-
Jun 18th, 2011, 01:53 PM
#3
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
-
Jun 18th, 2011, 02:27 PM
#4
Thread Starter
New Member
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.
Last edited by outlookvba; Jun 18th, 2011 at 02:56 PM.
-
Jun 18th, 2011, 02:43 PM
#5
Thread Starter
New Member
Re: Find and replace text with hyperlinks
 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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|