Extracting your MS Outlook tasks to XML

Since Santa brought me a new Palm Tungsten E2 last week, I've decided to move my task list (my "to-do's") from a custom application I built to Outlook (so they can be visible from my palm).

I wrote this little VBA code to extract the tasks from Outlook so that my old application could still be used to "view" my current tasks.

Public Sub ExportTasks()
On Error Resume Next
Dim strDirectory As String
Dim iFile2 As Integer
Dim dtDueDate As Date
Dim strPriority As String
Dim objNS As Outlook.NameSpace
Dim objTasks As Outlook.Items, objTaskFolder As Outlook.MAPIFolder
Dim objTask As Outlook.TaskItem
Dim strImportance As String
strOutputFile = "r:\download\tasks.xml"
Set objNS = Application.GetNamespace("MAPI")
Set objTaskFolder = objNS.GetDefaultFolder(olFolderTasks)
Set objTasks = objTaskFolder.Items
iFile2 = FreeFile
Open strOutputFile For Output As iFile2
Print #iFile2, ""
For Each objTask In objTasks
Select Case objTask.Status
Case olTaskComplete
strTaskStatus = "Complete"
Case olTaskDeferred
strTaskStatus = "Deferred"
Case olTaskInProgress
strTaskStatus = "In Progress"
Case olTaskNotStarted
strTaskStatus = "Not Started"
Case olTaskWaiting
strTaskStatus = "Waiting"
End Select
Select Case objTask.Importance
Case 2
strImportance = "High"
Case 1
strImportance = "Medium"
Case 0
strImportance = "Low"
End Select
dtDueDate = objTask.DueDate
Select Case Year(objTask.DueDate)
Case 4501
dtDueDate = Now() + 365
End Select
Print #iFile2, "" & objTask.Subject & "" & dtDueDate & "" & strTaskStatus & "" & strImportance & ""
Next
Print #iFile2, "
"
Close #iFile2
End Sub


The resulting XML Document:

<tasks>
<task>
<Subject>Call Home</Subject>
<DueDate>12/28/2005</DueDate>
<status>In Progress</status>
<importance>High</importance>
</task>
<task>
<Subject>What's next for Project X?</Subject>
<DueDate>1/4/2007</DueDate>
<status>In Progress</status>
<importance>Medium</importance>
</task>
<task>
<Subject>Speak with Manager about presenting in conference</Subject>
<DueDate>1/4/2007</DueDate>
<status>In Progress</status>
<importance>Low</importance>
</task>
<task>
<Subject>Database Documentation with Information Architect</Subject>
<DueDate>1/4/2007</DueDate><status>In Progress</status>
<importance>Low</importance>
</task>
</tasks>

Comments

Popular Posts