Outlook VBA -- Insert Email reference into new Task

  • Thread starter Thread starter Steve Newhouse
  • Start date Start date
S

Steve Newhouse

Hi guys,

I've written a script that creates a task from a selected email. It
puts the body of the email into the body of the task, but I also
wanted it to include a "reference" to the original email (like that
message icon perhaps) so I can link back to it. Anyone know how to do
this?

Here's the code:

-----------

Sub TaskFromEmail()

Dim item As MailItem
Set item = Outlook.Application.ActiveExplorer.Selection.item(1)

Dim olApp As Outlook.Application
Dim olTsk As TaskItem

Dim userField As Outlook.UserProperty
Dim userName As String

Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)

With olTsk
.Subject = item.Subject
.Status = olTaskNotStarted

'Need to insert reference to the original email in the new
task so I can link back to it
' ".Body = item" ' didn't work, neither did
".Attachments.Add item"

'Remove formatting
item.BodyFormat = olFormatPlain
.Body = Replace(item.Body, " " & vbCrLf, vbCr)

.Save

End With

Set olTsk = Nothing
Set olApp = Nothing

End Sub

-----------

P.S. -- You can see that I am removing formatting and attempting to
remove extra line breaks. This is because I was getting all kinds of
extra line breaks when copying the body from the email to the task.
Any way to keep the formatting but lose extra line breaks?
 
Back
Top