Excel1user
New Member
- Joined
- May 20, 2013
- Messages
- 6
I am writing vba code to create Outlook tasks for various employees from an Excel spreadsheet. The spreadsheet contains a list of reports under review and who is assigned to review the task.
I want the vba code to create an Outlook task for the individual assigned to review the report. I have found a number of websites with example code of how to do this, but everytime I have tried to use the code I get the same error on the "Recipients.Add" line. The error is vba "Run-time error '287': Application-defined or object-defined error".
Here is the code I'm using: (It is interesting to note that I have written code that successfully writes an e-mail, but that code uses the ".To" method, instead of the "Recipients.Add" method. Unfortunately the ".To" method is not available for Task Items.)
I want the vba code to create an Outlook task for the individual assigned to review the report. I have found a number of websites with example code of how to do this, but everytime I have tried to use the code I get the same error on the "Recipients.Add" line. The error is vba "Run-time error '287': Application-defined or object-defined error".
Here is the code I'm using: (It is interesting to note that I have written code that successfully writes an e-mail, but that code uses the ".To" method, instead of the "Recipients.Add" method. Unfortunately the ".To" method is not available for Task Items.)
Rich (BB code):
Option Explicit
Sub createtask()
Dim olApp As Outlook.Application, olNs As Outlook.Namespace, olTask As Outlook.TaskItem
Set olApp = Outlook.Application
Set olNs = olApp.GetNamespace("MAPI")
olNs.Logon
Set olTask = olApp.CreateItem(olTaskItem)
olTask.Assign
olTask.Subject = "Test"
olTask.Body = "Testing macro"
olTask.Recipients.Add ("myemail@myemail.com")
olTask.Display
End Sub
Last edited by a moderator: