PDA

View Full Version : Copy word contents to outlook object



outlukmacro
06-19-2011, 10:02 PM
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 in outlook mailitem.

i.e Incoming email -> Word Document -> change text to hyperlinks->Save changed WORD document to Outlook mail item

1. My code finds only the text in the document , but does not replace with a hyperlink.

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

My code here.

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 = "CSC[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[0-9][0-9][0-9][0-9][a-z][a-z]"
objSelection.Find.Execute

'Replace it with a hyperlink
ActiveDocument.Hyperlinks.Add Anchor:=objSelection.Range, _
Address:="Website URL" & objSelection.Text, _
TextToDisplay:=objSelection.Text

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

objMail.Body = objSelection.Paste
objMail.Save
Set objMail = Nothing
End Sub
Help would be greatly appreciated. Thanks a lot!!

outlukmacro
06-20-2011, 06:23 AM
Some one please reply to this question..

I have tried a lot..

Thanks