Visual Basic auto create task from email including attachments

Status
Not open for further replies.

carol1

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
I would like the email attachment to be included in the task. What would i need to add to the code below:

Sub ConvertMailtoTask(Item As Outlook.MailItem)
Dim objTask As Outlook.TaskItem
Set objTask = Application.CreateItem(olTaskItem)
objTask.Subject = Item.Subject
objTask.StartDate = Item.ReceivedTime
objTask.Body = Item.Body
objTask.Save
Set objTask = Nothing

End Sub
 

carol1

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Thank you. What code would i need to add to assign the task to a category filtered by the subject line.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
you mean "if subject = A, then category = A" "if subject = B, then category = B"?
 

carol1

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Yes thats what i want the code to do.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
You'd use the following lines in somewhere between the Set objtask = application and objtask.save lines.

If InStr(Item.Subject, "keyword") Then objTask.Categories = "keyword"

If InStr(Item.Subject, "keyword2") Then objTask.Categories = "keyword2"

You could split it to make it easier to manage - the three lines at the top, the objtask line before obj.save.

Dim strCat As String

If InStr(Item.Subject, "keyword") Then strCat = "keyword"

If InStr(Item.Subject, "more") Then strCat = "more"
objTask.Categories = strCat

Either of the above works for a few keywords, but if you need to use a lot, you need to use an array.

At the top:

Dim strCat As String

Dim arrCat As Variant

arrCat = Array("1keyword", "2keyword", "3keyword", "4keyword", "5keyword", "6keyword", "7keyword", "8keyword", "9keyword")

For i = LBound(arrCat) To UBound(arrCat)
If InStr(Item.Subject, arrCat(i)) Then strCat = arrCat(i)

Next i
before save:
objTask.Categories = strCat
 

carol1

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
I used the first code from your reply and it did not work for me. I'm not sure what I'm doing wrong. Would i be able to assign a category by the sender?
 

Forum Admin

Senior Member
Do you get any error messages?

InStr should be case-insensitive, but try using LCase(Item.subject) instead of Item.Subject and lower case keywords.

Yes, you can use any field -
If Item.SenderEmailAddress = "alias@domain.com" Then objTask.Categories = "keyword"

Note that this will not work for addresses on your exchange server -they don't have a smtp address.

BTW - if you want the message to remain unread in the Inbox, add the following before the end of the macro.
Item.UnRead = True
Item.Save
 

carol1

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
No error messages it just didnt assign the task to the category. My subject line will always start with [Ticket # then the rest of the subject line will vary. I used the following in my code as my keyword "[Ticket"
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
First test it with a simple category on every task it creates -

objTask.categories = "Test"

if that works, try

If left(item.subject, 9) = "[Ticket #" Then objTask.Categories = "Ticket"

ETA: put the code right before the objtask.save command.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
M Saving emails using Visual Basic - Selecting folder with msoFileDialogFolderPicker Outlook VBA and Custom Forms 6
M How to Create Macro in Visual Basic to add Contacts from Personal Folder Using Outlook 4
E trust access to visual basic project greyed out in outlook 2003 Outlook VBA and Custom Forms 1
S Visual indicator of a certain property or to show a macro toggle Outlook VBA and Custom Forms 2
K Visual of Tasks on desktop Using Outlook 2
D Outlook AddIn can't load outside Visual Studio Outlook VBA and Custom Forms 1
T Deploying add-ins from Visual Studio Tools for Office Outlook VBA and Custom Forms 2
U Outlook Addin Creation using Visual Studio 2008 Outlook VBA and Custom Forms 1
Christopher M " Basic Auth" Using Outlook.com accounts in Outlook 0
e_a_g_l_e_p_i Is there a way to add something that is in the "Format Text" tab to the "basic Text" on the message tab Using Outlook 1
Raewyn Basic accounting software? Using Outlook 2
A Basic BCM question about sync to Outlook 2013 BCM (Business Contact Manager) 1
D Basic pst file quesstion Using Outlook 1
D Vista Home Basic / Contact Manager 2003 BCM (Business Contact Manager) 1
nmanikrishnan Auto-reply from default account Using Outlook 1
A Imap account not auto syncing inbox at startup Using Outlook 0
K Run a script rule to auto 'send again' on undeliverable emails? Outlook VBA and Custom Forms 1
FryW Need help modifying a VBA script for in coming emails to auto set custom reminder time Outlook VBA and Custom Forms 0
S Auto forward for multiple emails Outlook VBA and Custom Forms 0
DDB VBA to Auto Insert Date and Time in the signature Outlook VBA and Custom Forms 2
V Auto-complete stopped working Using Outlook 4
D auto forward base on email address in body email Outlook VBA and Custom Forms 0
M Replyall macro with template and auto insert receptens Outlook VBA and Custom Forms 1
R Auto Forwarding with different "From" Outlook VBA and Custom Forms 0
P auto-complete is hopelessly broken Using Outlook 0
R Auto Assign Category colours to Incoming Emails based on whom the email is addressed Outlook VBA and Custom Forms 3
C Auto Run VBA Code on new email Outlook VBA and Custom Forms 1
S Outlook Macro to send auto acknowledge mail only to new mails received to a specific shared inbox Outlook VBA and Custom Forms 0
V Auto-Submitted: auto-replied in header Using Outlook 0
R Auto display of new email does not work on non-default account Outlook VBA and Custom Forms 0
B Outlook 2016 Auto-archive creates new folder Using Outlook 3
J Edit auto-complete list in Outlook 2016+/365? Using Outlook 0
P Auto assign shared mailbox Outlook VBA and Custom Forms 1
M Outlook 2010 Problem with OutLook 2010 32 bit, after Windows Auto Update Using Outlook 3
P [SOLVED] Auto remove [EXTERNAL] from subject Using Outlook 16
Z Add text to auto-forwarded e-mail Outlook VBA and Custom Forms 4
N Disable Auto Read Receipts sent after using Advanced Find Using Outlook 4
Q Prompt button to auto turn on Out of Office Outlook VBA and Custom Forms 3
P Auto Insert Current Date or Time into Email Subject Outlook VBA and Custom Forms 2
S Messages moved / deleted by auto-archive are not synchronized to exchange Exchange Server Administration 8
B Outlook 2010 is Auto Purging when not configured for that Using Outlook 1
M VBA to auto forward message with new subject and body text Outlook VBA and Custom Forms 8
A Auto Accept Meetings from the General Calendar Using Outlook 3
R auto send email when meeting closes from a shared calendar only Outlook VBA and Custom Forms 2
S auto-mapping mailboxes in outlook impacting an ost file? Exchange Server Administration 2
M Auto expand Distribution List Before Sending Email Outlook VBA and Custom Forms 1
M Auto-export mail to Excel Outlook VBA and Custom Forms 2
Ms_Cynic Auto-pasting email content in calendar appt? Using Outlook 2
R How Do I insert images in and Auto Reply Using Outlook 3
S Received mail as part of DL, need to auto-CC the same when replying Outlook VBA and Custom Forms 5

Similar threads

Top