Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6064953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:20:11+00:00 2026-05-23T09:20:11+00:00

After my thorough homework, I am posting this question. Please help me solve this..

  • 0

After my thorough homework, I am posting this question. Please help me solve this..

I want to search for ASA1234yy in the body of a text and replace it with the embedded hyperlink [ASA1234yy][1]
There can be many ids of this type in the body and each of theri hyperlinks should be unique which follows a pattern

Code done so far

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.code.com/ABCD")

Set RegX = Nothing
objMail.Body = RegExpReplace
objMail.Save
Set objMail = Nothing
End Sub

This code replaces the entire id only. How do I add the id to the hyperlink.
and after adding it, I need a embedded hyperlink.

thanks


Ok my modified idea below…

Hi..

I am facing two problems in the process described below..

Convert specified text extracted from Outlook mailitem to hyperlinks in word document and save it in outlook mailitem.

i.e Incoming email -> Save it in a Word Document -> Change text to hyperlinks-> Save changed WORD document to Outlook mail item

  1. My code finds only the first occuring text in the document , and replaces it with a hyperlink and leaves the other ocurrences

  2. After making modifications in the word document, I want to copy the contents of the document to the outlook mailitem.

  3. Formatting getting lost if email has tables and other stuff.

My code here for you…

Sub IncomingHyperlink(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
  Dim myObject As Object
  Dim myDoc As Word.Document
  Dim mySelection As Word.Selection

  strID = MyMail.EntryID
  Set objMail = Application.Session.GetItemFromID(strID)

  Set objWord = CreateObject("Word.Application")
  objWord.Visible = True

  Set objDoc = objWord.Documents.Add()
  Set objSelection = objWord.Selection
  objSelection.TypeText "GOOD" & objMail.Body

  With objSelection.Find
    .ClearFormatting
    .Text = "ASA[a-z][a-z][0-9][0-9][0-9][0-9][0-9]"
    .Forward = True
    .Wrap = wdFindAsk
    .MatchWildcards = True
  End With
  'Find next instance of Pattern "ASA[a-z][a-z][0-9][0-9][0-9][0-9]"
  objSelection.Find.Execute

  'Replace it with a hyperlink
  objSelection.Hyperlinks.Add Anchor:=objSelection.Range, _
  Address:="http://www.code.com/" & objSelection.Text, _
  TextToDisplay:=objSelection.Text

  objDoc.SaveAs ("C:\Desktop\testdoc.doc")
  objWord.Quit

  objMail.Body = objSelection.Paste
  objMail.Save
  Set objMail = Nothing
End Sub

Can you please help solve these two problems?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:20:11+00:00Added an answer on May 23, 2026 at 9:20 am

    Suggestion: just use Word’s built-in Find method.

    'Set up search
    With Selection.Find
        .ClearFormatting
        .Text = "ASA[0-9][0-9][0-9][0-9][a-z][a-z]"
        .Forward = True
        .Wrap = wdFindAsk
        .MatchWildcards = True
    End With
    
    ' Find next instance of Pattern "ASA[0-9][0-9][0-9][0-9][a-z][a-z]"
    Selection.Find.Execute
    
    ' Replace it with a hyperlink
    ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, _
        Address:="http://www.code.com/" & Selection.Text, _
        TextToDisplay:=Selection.Text
    

    The above will keep the orinigal text e.g. “ASA5534yy” and insert the hyperlink http://www.code.com/ASA5534yy (adjust as you see fit).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After having this question answered through a link to an external site , I
After reading this question , I was reminded of when I was taught Java
This is not a homework question, but rather my intention to know if this
Before I asked this question I had a look through the search results for
I just went through some MVC tutorials after checking this site out for a
One of my students asked me this kind of homework with C++ arrays. It
After going through the Appendix A, C# Coding Style Conventions of the great book
I'm trying to dig through some logs and need information before and after the
Is it allowable to pass parameters to a web page through the URL (after
Whats the normal procedure of clearing a form after POST? Just loop through the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.