sending a MS Outlook task item from Excel

Solar

Board Regular
Joined
Mar 11, 2003
Messages
90
I am designing a database with VBA user forms to input the data. This is all designed in an Excel spreadsheet. One of the options is to place a corrective action item in the database. THis item is paired with a responsible party and a due date.

I have not been able to figure out the syntax to create and send a MS Outlook task to the responsible party. I have code working that can send an email (thanks to TommyGun), but I cannot create the task or attach it to the email.

Any help would be appreciated.

Thanks!!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Try this and see if it works. It will send a task request to the recipient, and wait for their response. If this is not what you needed, then let me know.

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> SendTask()

<SPAN style="color:#00007F">Dim</SPAN> objOut <SPAN style="color:#00007F">As</SPAN> Outlook.Application
<SPAN style="color:#00007F">Dim</SPAN> objTask <SPAN style="color:#00007F">As</SPAN> Outlook.TaskItem
<SPAN style="color:#00007F">Dim</SPAN> blnCrt <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Boolean</SPAN>

<SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> CreateOutlook
<SPAN style="color:#00007F">Set</SPAN> objOut = GetObject(, "Outlook.Application")

CreateItem:
<SPAN style="color:#00007F">On</SPAN> <SPAN style="color:#00007F">Error</SPAN> <SPAN style="color:#00007F">GoTo</SPAN> 0

<SPAN style="color:#00007F">Set</SPAN> objTask = objOut.CreateItem(olTaskItem)

<SPAN style="color:#00007F">With</SPAN> objTask
    .Assign
    .Subject = "You need to fix this!"
    .Body = "Please fix this problem by " & Format(Now + 10, "mm/dd/yy")
    .DueDate = <SPAN style="color:#00007F">CDate</SPAN>(Now + 10)
    .Recipients.Add ("youremail@domain.com")
    .Send
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>

<SPAN style="color:#00007F">If</SPAN> blnCrt = <SPAN style="color:#00007F">True</SPAN> <SPAN style="color:#00007F">Then</SPAN> objOut.Quit

<SPAN style="color:#00007F">Set</SPAN> objTask = <SPAN style="color:#00007F">Nothing</SPAN>
<SPAN style="color:#00007F">Set</SPAN> objOut = <SPAN style="color:#00007F">Nothing</SPAN>

<SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN>

CreateOutlook:
<SPAN style="color:#00007F">Set</SPAN> objOut = CreateObject("Outlook.Application")
blnCrt = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">Resume</SPAN> CreateItem

<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 
Upvote 0
Something like this (reference to Outlook object model required):

Code:
Sub Test()

'declare and instanciate Outlook
Dim objOutlook As New Outlook.Application
'declare a task item
Dim objTask As Outlook.TaskItem

'create new task item
Set objTask = objOutlook.Session.GetDefaultFolder(olFolderTasks).Items.Add

'add reciptient name
objTask.Recipients.Add "First Last"

'Add subject
objTask.Subject = "Test"

'Add body
objTask.Body = "Test"

'set due date of tomorrow
objTask.DueDate = Now() + 1

'i don't know why but this step is necessary
objTask.Assign

'send the task
objTask.Send

'save it
objTask.Close olSave
End Sub
 
Upvote 0
Andrew, Assign is necessary to "give" the task to someone else. Otherwise, you will take ownership of the Task, and you cannot send it to another person. The Assign command allows you to watch the status of the task, but gives the ownership to the recipient.
 
Upvote 0
TommyGun said:
Andrew, Assign is necessary to "give" the task to someone else. Otherwise, you will take ownership of the Task, and you cannot send it to another person. The Assign command allows you to watch the status of the task, but gives the ownership to the recipient.

Oh, that wasn't me wondering. :wink: I just copied the code from a Google search.
 
Upvote 0
Thanks TommyGun!

One question though, what exactly do you meant that it will wait for the receipient's response?

Thanks
 
Upvote 0
Lookup tasks, assigning in your Outlook help file, and read the topic "About Task Assignments". It should answer your questions.
 
Upvote 0

Forum statistics

Threads
1,215,137
Messages
6,123,252
Members
449,093
Latest member
Vincent Khandagale

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top