Email to Task, move task to 'Other Tasks' folder to sync w/Sharepoint

M

mitcham

I need a VBA script that is executed via an Outlook 2007 rule when a specific
type of email is received (from a specific account, containing specific text).
The script should create an Outlook task with elements from the original
email (plus include the original email as an attachment), then move the task
to an 'Other Tasks' folder.

I have seen code somewhere that will created a task item from an email item.
But I have not seen anything that moves the task to a separate task folder
which, in this case, will synchronize with a Sharepoint 2007 site's task list.
Caveat: I know very little about programing VBA.

Ideas?
 
S

Sue Mosher [MVP-Outlook]

To create a new item in a non-default folder programmatically, use the Add
method on the target folder's Items collection:

Set newItem = targetFolder.Items.Add("IPM.Task.YourFormName")

To get a non-default folder (the targetFolder object), you need to walk the
folder hierarchy using the Folders collections or use a function that does
that for you. For examples, see:

http://www.outlookcode.com/d/code/getfolder.htm - uses a folder path string
http://www.outlookcode.com/codedetail.aspx?id=492 - searches for a folder by
name

To see the path for any folder, use View | Toolbars to display the Web
toolbar. The folder's path (prefixed with outlook:) will be displayed in the
address control on that toolbar.
 
M

Michael Bauer [MVP - Outlook]

To move an item use its Move function. Please see the VBA help for a code
sample.

--
Best regards
Michael Bauer - MVP Outlook

: VBOffice Reporter for Data Analysis & Reporting
: Outlook Categories? Category Manager Is Your Tool
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Fri, 08 Aug 2008 20:28:49 GMT schrieb mitcham:
 
T

TheBase

the following code contains two Subs,
Assign sub will:
- create the task
- add the email entry ID as a property to the task (as a reference)
- Attach the email to the task.
- Flag the orignal e-mail and add "Assigned task" to the top

Complete sub will:
- clear the flag from the email when the task is completed.

hope this will help... here is the code

Sub Assign()
'Get a reference to the MAPI namespace
Dim objNS As Outlook.NameSpace
Set objNS = Application.GetNamespace("MAPI")

' Get a reference to the currently selected Outlook folder
Dim currentFolder As Outlook.MAPIFolder
Set currentFolder = Application.ActiveExplorer.currentFolder


' Make sure at least one item is selected
If Application.ActiveExplorer Is Nothing Then
MsgBox "Please select an item"
Exit Sub
End If
If Application.ActiveExplorer.Selection Is Nothing Then
MsgBox "Please select an item"
Exit Sub
End If

'Get Selected Item
Dim oItem As Outlook.MailItem
Set oItem = Application.ActiveExplorer.Selection(1)

'Flag E-mail
oItem.FlagIcon = olBlueFlagIcon
oItem.FlagStatus = olFlagMarked
oItem.FlagRequest = "Assinged task on " & Now()

'Create a new task
Dim oTask As Outlook.TaskItem
Set oTask = Application.CreateItem(olTaskItem)

'Map task to e-mail using Email entry ID
Dim oProp As Outlook.UserProperty
Set oProp = oTask.UserProperties.Add("EmailEntryID", olText, True)
oProp.Value = oItem.EntryID

'Assing task properties
oTask.Subject = oItem.Subject
oTask.StartDate = Now()
oTask.Status = olTaskNotStarted
oTask.Attachments.Add oItem, olByValue
oTask.Assign

'open task
oTask.Display

'clear objects from the memory
Set objNS = Nothing
Set currentFolder = Nothing
Set oItem = Nothing
Set oTask = Nothing
Set oProp = Nothing
Set ojbAtt = Nothing
End Sub

Sub Complete()
On Error GoTo e
'Get a reference to the MAPI namespace
Dim objNS As Outlook.NameSpace
Set objNS = Application.GetNamespace("MAPI")
' Get a reference to the currently selected Outlook folder
Dim currentFolder As Outlook.MAPIFolder
Set currentFolder = Application.ActiveExplorer.currentFolder
'Get current task
Dim oSels As Outlook.Selection
Set oSels = Application.ActiveExplorer.Selection

Dim oTask As Outlook.TaskItem
Dim oProp As Outlook.UserProperty
Dim oEmail As Outlook.MailItem

For Each oSel In oSels
If oSel.Class = olTask Then
Set oTask = oSel
'Get referenced e-mail attached to the task

Set oProp = oTask.UserProperties.Find("EmailEntryID")
'Get e-mail by EntryID

Set oEmail = objNS.GetItemFromID(oProp.Value)
'Flag e-mail as compeleted
oEmail.FlagRequest = "Task Compeleted on " & Now()
oEmail.FlagIcon = olNoFlagIcon
oEmail.FlagStatus = olFlagComplete
'save changes
oEmail.Save
Set oTask = Nothing
Set oProp = Nothing
Set oEmail = Nothing
End If
Next
MsgBox "referenced e-mail has been flaged for completion successfully"
GoTo x
e:
MsgBox Err.Description
x:
'clear objects from the memory
Set objNS = Nothing
Set currentFolder = Nothing
Set oTask = Nothing
Set oProp = Nothing
Set oEmail = Nothing
End Sub
 

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