Create task automatically from email

M

Murphybp2

I am trying to create a process that will automatically create a task
from an incoming email message. My current approach uses a rule to
identify an email I have sent to myself, then runs a VBA Script.
Problem is I can't get the script to work, and am not skilled enough
to figure out why it is not working. If anyone can tell me what I
need to change to get it to work that would be great. Also, if
someone has a better approach, I'm open to suggestions. Thanks.




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
 
K

Ken Slovak - [MVP - Outlook]

Does the code get called?

What version of Outlook?

Have you stepped the code to see what's not working?

Are you sure those folder EntryID's are valid?

You realize that olmailitem is null? Also, Move is a function.

If you are using NameSpace twice you should instantiate a NameSpace object.

If you really want to move ti then save it before moving it.
 
M

Murphybp2

It is Outlook 2003. No I have not stepped through the code. I don't
know how to do that. I'm pretty sure the Entry ID's are valid. I
used a code someone else gave me that retrieves the entry id for the
folder. No, I don't realize that olmailitem is null. I don't know
what you mean when you say "Move is a function". I don't understand
what you are saying about NameSpace. I am a novice. I know how to
copy code that people give me, and maybe manipulate some basic
things. Other than that, I don't understand VBA. So if you could fix
the code for me that would help. Thanks.


Does the code get called?

What version of Outlook?

Have you stepped the code to see what's not working?

Are you sure those folder EntryID's are valid?

You realize that olmailitem is null? Also, Move is a function.

If you are using NameSpace twice you should instantiate a NameSpace object..

If you really want to move ti then save it before moving it.

--
Ken Slovak
[MVP - Outlook]http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Optionshttp://www.slovaktech.com/products.htm




I am trying to create a process that will automatically create a task
from an incoming email message.  My current approach uses a rule to
identify an email I have sent to myself, then runs a VBA Script.
Problem is I can't get the script to work, and am not skilled enough
to figure out why it is not working.  If anyone can tell me what I
need to change to get it to work that would be great.  Also, if
someone has a better approach, I'm open to suggestions.  Thanks.
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("00000000FB410B46958BD711B­21100805FA730C90100F8C9907DFE3BD611B20400805FA730C90000064BAD4F0000")
   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("00000000FB410B46958BD711B­21100805FA730C90100F7CBF61AE174914C9E364B416FA0A91600000154A1DB0000")

End Sub- Hide quoted text -

- Show quoted text -
 
J

JP

How about this approach? It checks your inbox for new emails, and then
creates a corresponding task. Note that it will do this for every
single email added to your Inbox. Also, Outlook has to be running for
it to work.

In the 'ThisOutlookSession' module, paste in this code: (assuming you
don't already have Startup Event code)

Private WithEvents Items As Outlook.Items
Private Sub Application_Startup()
Dim objNS As Outlook.NameSpace
Set objNS = Application.GetNamespace("MAPI")
Set Items = objNS.GetDefaultFolder(olFolderInbox).Items
End Sub
Private Sub Items_ItemAdd(ByVal Item As Object)
Dim objNS As Outlook.NameSpace
Set objNS = Application.GetNamespace("MAPI")

If TypeOf Item is Outlook.MailItem Then
Dim objTask As Outlook.TaskItem

Set objTask = CreateItem(olTaskItem)

With objTask
.Subject = Item.Subject
.StartDate = Now + 2
.Status = olTaskInProgress
.Importance = Item.Importance
.Body = Item.Body
.Save
End With

Set objTask = Nothing
Set objNS = Nothing
End Sub


HTH,
JP
 
K

Ken Slovak - [MVP - Outlook]

I can't just "fix" your code since I don't know what it's supposed to be
doing and I have no idea of whether or not the id's you're using would work.
I'd suggest getting a good beginners book on Outlook programming, like Sue
Mosher's book, and learning what you're doing from that.




It is Outlook 2003. No I have not stepped through the code. I don't
know how to do that. I'm pretty sure the Entry ID's are valid. I
used a code someone else gave me that retrieves the entry id for the
folder. No, I don't realize that olmailitem is null. I don't know
what you mean when you say "Move is a function". I don't understand
what you are saying about NameSpace. I am a novice. I know how to
copy code that people give me, and maybe manipulate some basic
things. Other than that, I don't understand VBA. So if you could fix
the code for me that would help. Thanks.
 
M

Murphybp2

Well, unfortunately, I don't have the time to study up on the
subject. I thought I had explained what I was trying to do, but let
me try again.

I want to be able to create a task in Outlook 2003 for certain email
messages based a certain criteria. The scenario is this. I am going
to send a message to someone and want to make sure to follow up on
what I ask them to do. So when I send the message, I also send a
blind copy to myself, by entering my name in the BCC field. When
this message is delivered to my inbox, I would like for the system to
automatically recognize that this is an email with my name in the BCC
field. Then to use that message to create a task. For the task, I
want the following things to happen.
1) Copy the original message into the body of the Task
2) Copy the name from the "To" field of the message into the subject
line of the Task
3) Then to copy the subject of the email message and put it in the
subject of the Task, after the name from # 2.
4) I want to populate the category field with the text "@Waiting".
5) I want to move the original email to a reference folder that I
have. ( which is where the entry ID comes from. I know this entry ID
is correct because I have other macros that move messages to this
folder that work).

I hope this gives a better idea of what I'm trying to do.
 
K

Ken Slovak - [MVP - Outlook]

I know what you want to do, but I'm not going to write your code for you.
 
M

Murphybp2

I know what you want to do, but I'm not going to write your code for you.

--
Ken Slovak
[MVP - Outlook]http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Optionshttp://www.slovaktech.com/products.htm




Well, unfortunately, I don't have the time to study up on the
subject.  I thought I had explained what I was trying to do, but let
me try again.
I want to be able to create a task in Outlook 2003 for certain email
messages based a certain criteria.  The scenario is this.  I am going
to send a message to someone and want to make sure to follow up on
what I ask them to do.  So when I send the message, I also send a
blind copy to myself, by entering my name in the BCC field.   When
this message is delivered to my inbox, I would like for the system to
automatically recognize that this is an email with my name in the BCC
field.  Then to use that message to create a task. For the task, I
want the following things to happen.
1) Copy the original message into the body of the Task
2) Copy the name from the "To" field of the message into the subject
line of the Task
3) Then to copy the subject of the email message and put it in the
subject of the Task, after the name from # 2.
4) I want to populate the category field with the text "@Waiting".
5) I want to move the original email to a reference folder that I
have.  ( which is where the entry ID comes from.  I know this entry ID
is correct because I have other macros that move messages to this
folder that work).
I hope this gives a better idea of what I'm trying to do.- Hide quoted text -

- Show quoted text -

Oh, ok then. You should have just said that in the first place rather
than lie about it. Thanks for the help....or lack there of. So much
for the concept of sharing knowledge on the internet.
 

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