How to loop through Outlook tasks in VBA

R

Rick Williams

I have a macro in MS Project that moves all the Project tasks to Outlook.
Now I need to be able to loop through all the tasks in Outlook so that I can
gather status info and use it to update MS Project. But I can't figure out a
way to get a reference to each Outlook task.

Can anyone help? I will gladly post the MSProject-to-Outlook-task code if
anyone wants to see it.

Thanks,
Rick Williams
 
G

Guest

You can iterate through all the Tasks in the default Tasks folder using a
macro like this:

Sub LoopThroughTasks()
Dim objTask As Outlook.TaskItem, objTaskFolder As Outlook.MAPIFolder
Dim objTaskItems As Outlook.Items, objNS As Outlook.NameSpace

Set objNS = Application.GetNamespace("MAPI")
Set objTaskFolder = objNS.GetDefaultFolder(olFolderTasks)
Set objTaskItems = objTaskFolder.Items

For Each objTask In objTaskItems
Debug.Print objTask.Status
'Returns value of olTaskStatus constants:
'olTaskComplete 2
'olTaskDeferred 4
'olTaskInProgress 1
'olTaskNotStarted 0
'olTaskWaiting 3
Next

Set objTask = Nothing
Set objTaskItems = Nothing
Set objTaskFolder = Nothing
Set objNS = Nothing
End Sub
 
R

Rick Williams

Thank you very much, Eric!
Rick Williams

Eric Legault said:
You can iterate through all the Tasks in the default Tasks folder using a
macro like this:

Sub LoopThroughTasks()
Dim objTask As Outlook.TaskItem, objTaskFolder As Outlook.MAPIFolder
Dim objTaskItems As Outlook.Items, objNS As Outlook.NameSpace

Set objNS = Application.GetNamespace("MAPI")
Set objTaskFolder = objNS.GetDefaultFolder(olFolderTasks)
Set objTaskItems = objTaskFolder.Items

For Each objTask In objTaskItems
Debug.Print objTask.Status
'Returns value of olTaskStatus constants:
'olTaskComplete 2
'olTaskDeferred 4
'olTaskInProgress 1
'olTaskNotStarted 0
'olTaskWaiting 3
Next

Set objTask = Nothing
Set objTaskItems = Nothing
Set objTaskFolder = Nothing
Set objNS = Nothing
End Sub

--
Eric Legault (Outlook MVP, MCDBA, old school WOSA MCSD, B.A.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/
 

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