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 & ""
Print #iFile2, "
Close #iFile2
End Sub

The resulting XML Document:

<Subject>Call Home</Subject>
<status>In Progress</status>
<Subject>What's next for Project X?</Subject>
<status>In Progress</status>
<Subject>Speak with Manager about presenting in conference</Subject>
<status>In Progress</status>
<Subject>Database Documentation with Information Architect</Subject>
<DueDate>1/4/2007</DueDate><status>In Progress</status>


Popular Posts