Create Outlook task in pst folder

Joined
Jun 22, 2008
Messages
1
Reaction score
0
I am using the following code to create an outlook task from an email. However, it creates the task in the default folder or mailbox. I am using several pst files and would like to create the task in one of them rather than my default mailbox. In this case, the pst is called 'Active' and the folders is called 'Tasks'. Thanks for your help!

------------
Public Sub CreateTaskBackup()
Dim olApp As Outlook.Application
Dim olTask As Outlook.TaskItem
'Using object rather than MailItem, so that it
'can handle posts, meeting requests, etc as well
Dim olItem As Object
Dim olExp As Outlook.Explorer
Dim fldCurrent As Outlook.MAPIFolder


Set olApp = Outlook.CreateObject("Outlook.Application")
Set olTask = olApp.CreateItem(olTaskItem)
Set olExp = olApp.ActiveExplorer
Set fldCurrent = olExp.CurrentFolder

Dim cntSelection As Integer
cntSelection = olExp.Selection.Count

For i = 1 To cntSelection
Set olItem = olExp.Selection.Item(i)
olTask.Attachments.Add olItem
olTask.Subject = "Follow up on " & olItem.Subject
olItem.Delete
Next
olTask.Save

End Sub
 
Back
Top