ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Create an Outlook Task (https://www.excelbanter.com/excel-programming/416719-create-outlook-task.html)

steven

Create an Outlook Task
 
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

Steve Yandl

Create an Outlook Task
 
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



"Steven" wrote in message
...
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




dan dungan

Create an Outlook Task
 
Hi Steven,

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

Dan

dan dungan

Create an Outlook Task
 
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

Steve Yandl

Create an Outlook Task
 
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


"dan dungan" wrote in message
...
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




dan dungan

Create an Outlook Task
 
Hi Steve,

I'm using Excel 2000. That probably explains it.

Thanks,

Dan


All times are GMT +1. The time now is 07:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com