VBA Script that copies incoming message to task

M

Murphybp2

I am trying to create a process where when I send a message that I
want to be sure to follow up on, I cc myself on the message. I want
to then take that incoming message, copy it to a task and populate
certain fields on the task, then delete the message. I am currently
trying to run the script after a rule identifies the message. If
there is a better way of doing it, I'm open to suggestions. Below is
the script I have, but it's not working, and I can't figure out what
the problem is. Any help would be appreciated.


Sub CopyIncomingEmailtoWaitingForTask(Item As Outlook.MailItem)
'Use this to tie to a Rule that automatically creates task for Waiting
Items on Incoming items I copied myself on

Dim olmailitem As Outlook.MailItem
Dim ti As TaskItem
Dim fldCurrent As MAPIFolder
Set fldCurrent =
Application.GetNamespace("MAPI").GetFolderFromID("00000000FB410B46958BD711B21100805FA730C90100F8C9907DFE3BD611B20400805FA730C90000064BAD4F0000")

Set ti = fldCurrent.Items.Add
ti.Body = olmailitem.Body & vbCrLf & vbCrLf
ti.Attachments.Add MailItem
ti.Subject = olmailitem.SenderName & olmailitem.Subject &
olmailitem.SentOn
ti.Categories = "@Waiting For"

olmailitem.Move
Application.GetNamespace("MAPI").GetFolderFromID("00000000FB410B46958BD711B21100805FA730C90100F7CBF61AE174914C9E364B416FA0A91600000154A1DB0000")

ti.Save

End Sub
 
J

JP

You could use the ItemSend event to grab a copy of the message and
copy it to your default Tasks folder (which would turn it into a
task).

For example:

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As
Boolean)
Dim objNS As NameSpace
Dim TaskFldr As MAPIFolder
Dim recip As Recipient

Set objNS = Application.GetNamespace("MAPI")
Set TaskFldr = objNS.GetDefaultFolder(olFolderTasks)

If TypeName(Item) = "MailItem" Then
Set Msg = Item
For Each recip In Msg.Recipients
If recip.Name = "Jimmy Pena" Then
Set mymsg = Msg.Copy
mymsg.Move TaskFldr
End If
Next recip
End If


HTH,
JP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top