Send Email to Task while sending to Email address

A

Ashley

I have created a custom form in Outlook and I would like to create a macro that when the email is sent, it also creates an outlook task from the email.

I have create the code below that works if I send the email to myself and then open it and run the macro. I think my problem is that I using MailItem and at the point I am trying to run the marco the email hasn't been sent. I may need to use CurrentItem but I can't seem to get the code right. Help...


Sub TaskFromEmail()

Dim item As MailItem
Set item = Outlook.Application.ActiveExplorer.Selection.item(1)


Dim olApp As Outlook.Application
Dim olTsk As TaskItem
Dim userField As Outlook.UserProperty

Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)


With olTsk
.Subject = item.Subject
.Status = olTaskNotStarted
.Body = item.Body
'This is a custom field to update DueDate in the Task
Set ups = item.UserProperties
Set prp = ups.Find("DateDue")
.DueDate = ups("DateDue").Value


.Save
End With

Set olTsk = Nothing
Set olApp = Nothing

End Sub

Submitted using http://www.outlookforums.com
 
M

Michael Bauer [MVP - Outlook]

If you want the code to run automatically, call it from the ItemSend event.
There use the passed Item variable instead of Selection.Item(1).

And the (Outlook) Application object exists already. there's no need to set
another variable to a New Outlook.Application object.

--
Best regards
Michael Bauer - MVP Outlook
Category Manager - Manage and share your categories:
SAM - The Sending Account Manager:
<http://www.vboffice.net/product.html?lang=en>


Am Wed, 07 Apr 2010 12:22:54 -0400 schrieb Ashley:
I have created a custom form in Outlook and I would like to create a macro
that when the email is sent, it also creates an outlook task from the email.
I have create the code below that works if I send the email to myself and
then open it and run the macro. I think my problem is that I using MailItem
and at the point I am trying to run the marco the email hasn't been sent. I
may need to use CurrentItem but I can't seem to get the code right. Help...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top