View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Steve Yandl Steve Yandl is offline
external usenet poster
 
Posts: 284
Default Specify an Outlook folder for already successful Task creation procedure

Rather than use
Set olTask = olApp.CreateItem(olTaskItem)
you want to get the folder and then
objFolders.Items.Add

Below is an example of a sub that you should be able to modify. This is
adding tasks to a subfolder of my 'Tasks' folder that I've named "Very
Important"

________________________________

Sub LoadTasks()

Const olFolderTasks = 13

Dim r As Integer
Dim x As Integer

r = Range("A65536").End(xlUp).Row

Set ol = CreateObject("Outlook.Application")
Set ns = ol.GetNamespace("MAPI")
Set olFolderDF = ns.GetDefaultFolder(olFolderTasks)
Set olFolder = olFolderDF.Folders("Very Important")

For x = 1 To r
Set taskItem = olFolder.Items.Add
With taskItem
.Subject = Sheets("Sheet1").Cells(x, 1).Value
.DueDate = Sheets("Sheet1").Cells(x, 2).Value
.Save
End With
Next x

Set taskItem = Nothing
Set ns = Nothing
Set ol = Nothing

End Sub

_________________________________

Steve



"Finny388" wrote in message
oups.com...
On Oct 3, 3:45 pm, Finny388 wrote:
On Oct 3, 12:55 pm, Finny388 wrote:



I am using the following to succefully create tasks within Outlook but
only to the default Task folder.
How can I specify to save the task to a particular task folder?


Sub AddTasksToOutlook()
'!! Reference to Outlook object library required !!


Dim olTask As Outlook.TaskItem
Dim olApp As Outlook.Application
Dim lngRow As Long, shtSource As Worksheet


'Get reference to MS Outlook
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err.Number < 0 Then
Set olApp = CreateObject("Outlook.Application")
End If
On Error GoTo 0
Set shtSource = ActiveSheet


'Enter number of orders to process in A1
For lngRow = 2 To shtSource.Cells(1, 1).Value + 1
Set olTask = olApp.CreateItem(olTaskItem)
With olTask
.Subject = shtSource.Cells(lngRow, 2) + " " +
shtSource.Cells(1, 3)
.DueDate = CDate(DateValue(shtSource.Cells(lngRow, 3))) ' +
shtSource.Cells(lngRow, 6))
.Categories = "Purchase Orders"
.Save
End With
Next lngRow
End Sub


^


anyone know how to do this? It would be a great help. tia