Hyperlink formatting lost after replacement in outlook

Status
Not open for further replies.

outlookmacro

Member
Outlook version
Email Account
Exchange Server
I have written a code which replaces the text of certain format into a hyperlink. This code is invoked by a rule during an Incoming email.

Incoming email -> copy the email to word editor -> make necessary changes -> copy from word editor to outlook mail item(replaced hyperlinks gets lost in mail item, while newly added text reamins intact)

My code is below for your refernce..

this code replaces only the first occurrence of the needed text and does not replace others.

Please help solve these problems. Thank you...

I have tried out different options and still not able to get it work.
 
Sub IncomingHyperlink(MyMail As MailItem)

Dim strID As String

Dim Body As String

Dim objMail As Outlook.MailItem

Dim myObject As Object

Dim myDoc As Word.Document

Dim mySelection As Word.Selection

strID = MyMail.EntryID

Set objMail = Application.Session.GetItemFromID(strID)

'Creates word application

Set objWord = CreateObject("Word.Application")

objWord.Visible = True

Set objDoc = objWord.Documents.Add()

Set objSelection = objWord.Selection

'Copies contents of email into word document

objSelection.TypeText "GOOD" & objMail.HTMLBody

With objSelection.Find

> ClearFormatting

> Text = "ASA[0-9][0-9][0-9][0-9][a-z][a-z]"

> Forward = True

> Wrap = wdFindAsk

> MatchWildcards = True

End With

objSelection.Find.Execute

objSelection.Hyperlinks.Add Anchor:=objSelection.Range, _

Address:="http://www.code.com/" & objSelection.Text, _

TextToDisplay:=objSelection.Text

'Copies contents to email item from word document

objMail.HTMLBody = objDoc.Range(0, objDoc.Range.End)

objMail.Save

Set objMail = Nothing

End Su
I have written a code which replaces the text of certain format into a hyperlink. This code is invoked by a rule during an Incoming email.

Incoming email -> copy the email to word editor -> make necessary changes -> copy from word editor to outlook mail item(replaced hyperlinks gets lost in mail item, while newly added text reamins intact).
 
I don't see a loop for the selection.find. Its stopping after the first find.




I use Selection.WholeStory in one word macro to solve the problem. On another i use a do while selection.find.execute and then loop. The do while requires me to to make sure I'm at the top of the page or it will skip the things above it.
 
I don't see a loop for the selection.find. Its stopping after the first find.

Thanks for your reply.

I use Selection.WholeStory in one word macro to solve the problem. On another i use a do while selection.find.execute and then loop. The do while requires me to to make sure I'm at the top of the page or it will skip the things above it.

I tried using Selection.WholeStory but it does not work. Can you provide me a sample code for the second option.

Also, do you have any idea, why the text when copied to outlook object loses its replaced hyperlink format while other changes remain intact in outlook object

Help on this is greatly appreciated.

Thanks
 
My selection.wholestory code is






Sub name()
Selection.WholeStory

With Selection.Find
.Text = "words"
.Replacement.Text = "different word"
End With
Selection.Find.Execute Replace:=wdReplaceAll




End sub






And a different macro with a loop - i'm deleting an entire paragragh here. the first part finds the para that begind with a certain word, selects it then backspaces.


Private Sub NAME()




Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Name:="1"




Selection.Find.ClearFormatting
With Selection.Find
.Text = "words"
.Forward = True
End With




Do While Selection.Find.Execute
Selection.Paragraphs(1).Range.Select
Selection.TypeBackspace


Loop




End Sub
 
Thanks for the helper code. In the first code, how to add the code with just hyperlink.

For Eg: If ASA1234yy is the found pattern, it should be replaced with just ASA1234yy, but clicking on it should take me to www.code.com/ASA1234yy/xyz.

Also, am I copying the contents of the word document to the outlook item in a right fashion?(because I am not able to get the replaced hyperlink in the word document)

Thanks a lot!
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
O Hyperlink formatting lost after replacement in outlook Using Outlook 0
C No Hyperlink when Sharing an article from the Web Using Outlook 3
V Embedding hyperlink into Word document Using Outlook 2
Y Open and Save Hyperlink Files in multiple emails Outlook VBA and Custom Forms 9
L Ignore hyperlink from being flagged as false pattern Outlook VBA and Custom Forms 3
D Custom form with html hyperlink Outlook VBA and Custom Forms 7
N open the hyperlink in Outlook directly instead of browser Using Outlook 1
M VBA Rule for removing all body but hyperlink then forwarding Outlook VBA and Custom Forms 9
M How to view the URL for a hyperlink? Using Outlook 1
A Add Hyperlink to Task Outlook VBA and Custom Forms 11
Q Why can't I copy image with embedded hyperlink from email to Word Using Outlook 0
P URL Hyperlink not working correctly in Outlook 2003 Using Outlook 10
A Create Macro for hyperlink(email) in message body Outlook VBA and Custom Forms 9
Diane Poremsky Disable the Unsafe Hyperlink Warning when Opening Attachments Using Outlook 0
V Using custom field data in mail body + mailto hyperlink Outlook VBA and Custom Forms 7
C Hyperlink to an Outlook search Using Outlook 1
makinmyway Recent Files Not Updating when Using Insert Hyperlink in Outlook 2013 Using Outlook 0
E Create a URL hyperlink in an Outlook custom form? Outlook VBA and Custom Forms 2
J Macro generating email using default signature and hyperlink Outlook VBA and Custom Forms 5
Witzker HYPERLINK "mailto:test@test.com" in form body Using Outlook 21
Hudas Hyperlink Saved Outlook Email to MS Access Table Using Outlook 4
D Particular Facebook "Hyperlink" Issue In Office 2010 Outlook (32 bit) Using Outlook 5
S email body without "HYPERLINK" ( vba ) Using Outlook 6
M How to create a hyperlink to to an organizational form Using Outlook 5
J Hyperlink VBA Using Outlook 1
P Can't add a custom hyperlink to toolbar in OL 2010 Using Outlook 1
T Desable Hyperlink on email Using Outlook 3
G Hyperlink Using Outlook 1
T Hyperlink Issue Using Outlook 2
P Hyperlink to Access record/Form Outlook VBA and Custom Forms 2
M auto click hyperlink?! Outlook VBA and Custom Forms 1
M Auto click a hyperlink Outlook VBA and Custom Forms 2
R Inserting a hyperlink in the bod of an outlook appt. Outlook VBA and Custom Forms 13
K Add Hyperlink in Email Body by VBA Outlook VBA and Custom Forms 1
M A plug in (or method) to keep email message formatting after it expires Using Outlook 1
C View doesn't refresh (fields or formatting) Using Outlook 1
V Can one change the formatting of email title blocks? Using Outlook 0
N Help creating a VBA macro with conditional formatting to change the font color of all external emails to red Outlook VBA and Custom Forms 5
K Outlook tasks formatting Using Outlook 4
E Conditional formatting - when current account <> received account ? Using Outlook 3
V Outlook Forms: Formatting a Label with 2 different styles Outlook VBA and Custom Forms 1
P BCM conditional formatting BCM (Business Contact Manager) 5
S Conditional Formatting for messages in a Conversation thread Using Outlook 1
S Conditional Formatting in calendar part of To-Do Bar Using Outlook 1
S Conditional formatting problem with "is not empty" and categories Using Outlook 2
N How to remove signature formatting from Text in Word (accidentally taken from Outlook) Using Outlook 0
K Conditional Formatting based on Department of person received from? Outlook VBA and Custom Forms 4
M Using conditional formatting on a shared calendar with categories Using Outlook 6
L Email to task without changin formatting Outlook VBA and Custom Forms 16
K Paste from Windows Clipboard then change font without losing formatting Outlook VBA and Custom Forms 1

Similar threads

Back
Top