Results 1 to 5 of 5

Thread: Find and replace text with hyperlinks

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2011
    Posts
    5

    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

  2. #2

    Thread Starter
    New Member
    Join Date
    Jun 2011
    Posts
    5

    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.

  3. #3
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2011
    Posts
    5

    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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Jun 2011
    Posts
    5

    Re: Find and replace text with hyperlinks

    Quote Originally Posted by Spoo View Post
    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
  •  



Click Here to Expand Forum to Full Width