Automate task list export.

  • Thread starter Thread starter Ciaron Nixon
  • Start date Start date
C

Ciaron Nixon

Any suggests for this problem:
I want Outlook (2003) to automatically export my Tasks list to a text file
(or html) everytime i shut outlook down. any ideas?

cheers,
-ciaron
 
Unfortunately, you can't automate the Import/Export Wizard, or else this
would be fairly straightforward. What you can do is pump some code into the
Application_Quit event to export your Tasks. Call this procedure from there
(make sure you have a reference to the Microsoft Scripting Runtime library
set in the project):

Sub ExportTasks()
On Error Resume Next

Dim objNS As Outlook.NameSpace
Dim objTasks As Outlook.Items, objTaskFolder As Outlook.MAPIFolder
Dim objTask As Outlook.TaskItem
Dim objFS As Scripting.FileSystemObject, objOutputFile As
Scripting.TextStream
Dim strTaskStatus As String

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

Set objFS = New Scripting.FileSystemObject
Set objOutputFile = objFS.OpenTextFile("C:\Temp\TaskExport.csv",
ForWriting _
, True)

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
'Note: empty DueDate values are actually '1/1/4501'
'You can check IsRecurring to ignore recurring tasks
objOutputFile.WriteLine objTask.Subject & "," & objTask.DueDate &
"," & strTaskStatus
Next
objOutputFile.Close
End Sub
 
Back
Top