Macro in Excel to Create a Outlook Task


Posted by Dan Royer on December 23, 2001 1:01 PM

I need to write a macro to create a Outlook task in Excel. I know it can be done. Could someone help me in this quest?

Posted by Paulus Liem on December 23, 2001 7:39 PM

try this one:
Sub oltask()

Dim olap As Outlook.Application
Dim oltask As Outlook.TaskItem

On Error Resume Next
' check if Outlook is running
Set olap = GetObject("outlook.application")
If Err <> 0 Then
'if not running, start it
Set olap = CreateObject("outlook.application")
End If

'set a new task
Set oltask = olap.CreateItem(olTaskItem)
With oltask
.Subject = "Christmas Dinner"
.DueDate = "12/25/01"
.StartDate = "12/25/01"
.ReminderSet = "12/25/01"
.ReminderTime = "18:00:00"
.Display ' if you want to display it
End With

Set olap = Nothing
Set oltask = Nothing

End Sub



Posted by Ivan F Moala on December 23, 2001 8:29 PM

Note: As you are using earlybinding you'll need
to reference the Outlook Object library

Just add this code to do it.


Sub MakeLibrary_outlook()

ThisWorkbook.VBProject.References.AddFromGuid _
"{00062FFF-0000-0000-C000-000000000046}", 9, 0

End Sub


Assuming Outlook 2000!


HTH

Ivan 'set a new task Set oltask = olap.CreateItem(olTaskItem) With oltask .Subject = "Christmas Dinner" .DueDate = "12/25/01" .StartDate = "12/25/01" .ReminderSet = "12/25/01" .ReminderTime = "18:00:00" .Display ' if you want to display it End With Set olap = Nothing Set oltask = Nothing