PDA

View Full Version : Excel generate a task in Outlook



ukdane
09-23-2009, 12:35 AM
Hi,
I've previously had success with generating an appointment in Outlook, via Excel (see thread here: http://www.vbaexpress.com/forum/showthread.php?t=25423&highlight=calendar)

However, my client now wants the details to be compiled as a TASK in outlook, instead of an appointment.

How do I change the code in order to be able to use it to generate a task?

What are the various OL item names (ie in Contacts, OLAppointment.Subject refers to the subject line)?

Thansk for your help.

Bob Phillips
09-23-2009, 01:44 AM
Sub Tasks()
Const olAppointmentItem As Long = 1
Const olTaskItem As Long = 3
Dim OLApp As Object
Dim OLNS As Object
Dim OLTask As Object

On Error Resume Next
Set OLApp = GetObject(, "Outlook.Application")
If OLApp Is Nothing Then Set OLApp = CreateObject("Outlook.Application")
On Error GoTo 0

If Not OLApp Is Nothing Then

Set OLNS = OLApp.GetNamespace("MAPI")
OLNS.Logon

Set OLTask = OLApp.CreateItem(olTaskItem)
OLTask.Subject = Range("A1").Value
OLTask.StartDate = Range("B1").Value
OLTask.DueDate = Range("C1").Value
OLTask.ReminderTime = Range("D1").Value
OLTask.Save

Set OLTask = Nothing
Set OLNS = Nothing
Set OLApp = Nothing
End If

End Sub