Hello!
I need to paste links to outlook emails in some documents. To get links to mails I wrote such macro, that copies the internal message ID and creates a right link(like Outlook:3HDF8EWJE8FJ) but I can't make macro that wil push this link like hyperlink to buffer
The correct macro that copy the normal link and the subject:
Sub CopyLink()
Dim objMail As Outlook.MailItem
Dim doClipboard As DataObject
Set doClipboard = New DataObject
If Application.ActiveExplorer.Selection.Count <> 1 Then
MsgBox ("Select 1 object")
Exit Sub
End If
Set objMail = Application.ActiveExplorer.Selection.Item(1)
doClipboard.SetText "[[outlook:" + objMail.EntryID + "][MESSAGE: " + objMail.Subject + " (" + objMail.SenderName + ")]]"
doClipboard.PutInClipboard
End Sub
I tried to push the hyperlink to the buffer this way, but it's not working:
Sub CopyLink()
Dim objMail As Outlook.MailItem
Dim doClipboard As DataObject
Set doClipboard = New DataObject
If Application.ActiveExplorer.Selection.Count <> 1 Then
MsgBox ("Select 1 object")
Exit Sub
End If
Set objMail = Application.ActiveExplorer.Selection.Item(1)
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:= _
"outlook:" + objMail.EntryID, SubAddress:="", ScreenTip:="", TextToDisplay:=objMail.SenderName
Selection.Copy
End Sub
P.S. Sorry for my bad English