Create an Outlook Task

S

Steven

I want to set up a task through excel.
I get an error:
User defined type not defined on the objTask As Outlook.TaskItem
on the following.

Sub createTask()
Dim objTask As Outlook.TaskItem
Set objTask = OutApp.CreateItem(olTaskItem)
With objTask
.StartDate = "05/30/2008"
.DueDate = "05/31/2008"
.Subject = "Testing Task"
.Body = "Testing Task"
.Assign
.Recipients = "Employee Name"
.Send
End With
Set objTask = Nothing
End Sub


How do I correct this?

Thank you,

Steven
 
S

Steve Yandl

Steven,

I've had better luck grabbing the Tasks folder and then using the 'add'
method of the 'items' collection. The sample below is a routine I use to
create multiple tasks.

' _________________________________

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 olFolder = ns.GetDefaultFolder(olFolderTasks)

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 Yandl
 
D

dan dungan

Hi Steven,

In the vbe under tools, is the reference set to Microsoft Outlook 9.0
Object Library?

Dan
 
D

dan dungan

Hi Steve,

When I tried the code sample

I had to dim ol and ns

so I did it like this:
Const olFolderTasks = 13

Dim ol As Application
Dim ns As NameSpace
Dim r As Integer
Dim x As Integer

Excel returned the compile error: Assignment to a constant not
permitted on

Set olFolder = ns.GetDefaultFolder(olFolderTasks)

Should I have done something differently?

Dan
 
S

Steve Yandl

Having to dim ol and ns doesn't surprise me, you probably have 'option
explicit' set (I probably should as well). I'm not sure why you're not
allowed to use the constant to grab the 'Tasks' folder. I'm running Office
2003, perhaps this is a version issue????

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top