Code to move task from inbox to a task folder



I'm trying to automate my Outlook mailbox so when a task appears in my inbox
with the subject

starting with "Please consider" that it is moved to my task folder named

My direction is that I've created an Outlook Rule whose criteria is having
"Please consider" in

the subject and then it runs a script.

The script needs to move the task for me, but this is where I'm having
problems since I'm

limited to what I know.

Below is my snippet which only works if I go into the task folder, highlight
all the entries

and run the code.

Sub MoveTaskToFolder()
On Error Resume Next

Dim objFolder As Outlook.MAPIFolder, objInbox As Outlook.MAPIFolder
Dim objNS As Outlook.NameSpace, objItem As Outlook.TaskItem

Set objNS = Application.GetNamespace("MAPI")
Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
Set objFolder = objInbox.Parent.Folders("AAA")

For Each objItem In Application.ActiveExplorer.Selection
If objFolder.DefaultItemType = olTaskItem Then
objItem.Move objFolder
End If

Set objItem = Nothing
Set objFolder = Nothing
Set objInbox = Nothing
Set objNS = Nothing

End Sub

Can anyone help me with this.

Sue Mosher [MVP-Outlook]

A procedure for use with a "run a script" rule action needs a MailItem or MeetingItem as its parameter. That item is processed by the code. For example:

Sub RunAScriptRuleRoutine(MyMail As MailItem)
Dim strID As String
Dim olNS As Outlook.NameSpace
Dim msg As Outlook.MailItem
Dim rply as Outlook.MailItem

strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set msg = olNS.GetItemFromID(strID)
' do stuff with msg, e.g.
Set rply = msg.Reply
rply.Body = "What you want the reply to say."
rply.To = "(e-mail address removed); (e-mail address removed)"

Set msg = Nothing
Set rply = Nothing
Set olNS = Nothing
End Sub

You might also want to take a look at the sample at, which takes a different approach to what you're trying to do.


First of all Sue, thank you for your assistance. You have helped me many
times in the past.

Since neither MailItem or MeetingItem will work for an incoming task (I
tested it), I assume using a "run a script" rule is not an option.

So at this point, I'm not even sure of a direction. All I really want to
accomplish is when I receive new task with "Please consider" in the subject,
I want to accept these tasks and move them to a task folder named "AAA".

If there's any other direction someone can suggest or code someone could
provide for this I would greatly appreciate it.

Thanks again!


Sue Mosher [MVP-Outlook]

Sorry, I misread your original message and thought that "a task appears in my inbox" meant a message that you wanted to turn into a task. You're right, a rule won't work for a TaskRequestItem. You'd need to use either the NewMailEx event or Items.ItemAdd on the Inbox; both are covered at

Once you have an incoming item, check its Class property to determine whether it's a task request (and the Subject, too, of course). You can then use the TaskRequest.GetAssociatedTask to return the TaskItem. Use the Respond method to accept the task. Its Move method will move it to another folder.

Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators

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