How to replace text in the body of an incoming message with a hyperlink in Outlook 2010?

  • ikathegreat

    Does anyone know of a way or a program that will read a received email and recognize a static format of text (in my case it will be "#" followed by 6 integers), and make that a hyperlink to a webpage?

    I have to think something similar exists. This would operate in the same fashion that when you type "" and then hit Enter or space, it automatically converts this into a hyperlink. That is for a composed email, I'm looking for this in received emails.

  • Answers
  • allquixotic

    You trying to automatically hyperlink to bugs in your bug/defects tracking application?

    Easiest thing to do would be to modify the software sending the email to create the hyperlinks itself...

    If you still want to do it manually, here's a quick guide I hacked together that seems to work (tested VERY lightly, but it does nominally do what it's designed to do).

    Step 1: Enable the Developer tab in the Ribbon

    Click Options: click Options

    Click Customize Ribbon, then click the Developer checkbox: click Customize Ribbon

    Step 2: Go to VBA and put in the code

    Click Visual Basic:
    Go to Visual Basic

    Double click on the ThisOutlookSession module and paste in the code as follows: Put in the code

    And now, the code:

    Option Explicit
    Sub InsertHyperLink(MyMail As MailItem)
        Dim body As String, re As Object, match As Variant
        body = MyMail.body
        Set re = CreateObject("vbscript.regexp")
        re.Pattern = "#[0-9][0-9][0-9][0-9][0-9][0-9]"
        For Each match In re.Execute(body)
            body = Replace(body, match.Value, "" & Right(match.Value, 6), 1, -1, vbTextCompare)
        MyMail.body = body
    End Sub

    Click the Save icon or press Ctrl+S.

    Step 3: Create a Custom Rule executing a Script.

    Go to Manage Rules & Alerts: Go to Manage Rules & Alerts

    Click New Rule...: Click New Rule...

    Click "Apply rule on messages I receive", then click Next: Apply rule on messages I receive

    If you want to only run the rule on certain messages, you can select from any of the conditions here. Don't worry about filtering on messages containing "#123456" in the body; we do that in the code. So just filter on, for example, "From:" or the Subject, if you want. This is optional. Select conditions

    Choose "Run a script". Click on the text that says "a script" in blue underline in the bottom box. Run a script action

    Pick the script we just created, whose name will probably be cut off due to the small dialog, but that's OK.

    Pick your script

    At this point, you can just click "Next" and "Finish" at the bottom repeatedly until the dialogs go away; you should be done.

    Now try and compose an email to yourself (or receive an email from the sender or subject line you're expecting, if you specified a custom condition) and insert a number like:


    into the body, and send it.

    When you get the mail message, it should have it as a URL to (where "123456" is replaced with the 6 numbers you chose).

    You can customize the script code to point to a different URL by modifying the URL string within the code. You can also do more exotic things with it to either keep or remove the number, or various other things.

    This answer took my entire lunch hour, so if you think it was worthwhile, please remember to vote up... Let me know in the comments if you have any difficulties or questions.

    Very Helpful StackOverflow question, which at least gave me a feasibility approach for implementing this: #95625

  • Related Question

    windows 7 - Outlook 2010 auto responder rule not working (Error)
  • Questioner

    In Outlook 2010 on Windows 7 I've created a template to use as an auto responder and I set a rule to respond using the template if my name is in the "to line".

    Upon receiving any message the rule reports an error but gives no explanation of what the error is.

    My goal here is simply to make an auto responder, if there is a simpler way/workaround I would love any help getting the to work as I am leaving town very shortly.

  • Related Answers
  • Holocryptic

    You are correct that a POP account cannot use the Out of Office reply. But the link I posted in the comment section, or this one from MSFT explain how to set up a work around for your situation. You'll need to have Outlook running for it to work however, and configure it to automatically check for messages.