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.
Thread starter Similar threads Forum Replies Date
M How to Create Macro in Visual Basic to add Contacts from Personal Folder Using Outlook 4
F Trust access to visual basic project greyed out in outlook 2003 Using Outlook 1
E trust access to visual basic project greyed out in outlook 2003 Outlook VBA and Custom Forms 1
K Visual of Tasks on desktop Using Outlook 2
B Microsoft Visual C++ Runtime Library message, "This application has requested the Runtime to termina Using Outlook 1
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
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
H Another OWA Timeout thread - possible Forms/Basic Authentication with IIS issue Exchange Server Administration 1
C SBS 2003 Outlook Anywhere Basic Authentication Issue Using Outlook 2
A Some Basic Setting in Exchang server Exchange Server Administration 4
M Re: Outlook Anywhere | NTLM and BASIC Exchange Server Administration 3
J Outlook (Office 2007 Basic) exits when I close an email or appointment. Using Outlook 2
M NTLM AND Basic Authentication for Outlook Anywhere (both) Exchange Server Administration 16
M Outlook Anywhere - Enable both NTLM and Basic Authentication Exchange Server Administration 8
D Vista Home Basic / Contact Manager 2003 BCM (Business Contact Manager) 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 4
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 14
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
T Have Outlook 2016 suggest email address auto complete entries directly from the user's contacts list Using Outlook 10
T Have Outlook 2016 suggest email address auto complete entries directly from the user's contacts list Using Outlook 0
P Auto scroll to specific folder in Folder Pane Outlook VBA and Custom Forms 3
C Auto categorize duplicate subjects Outlook VBA and Custom Forms 11
N Auto-complete - block select emails Using Outlook 3
C Auto save outlook attachments when email is received Outlook VBA and Custom Forms 1
J HELP- Rule to auto strip prepend from external emails Using Outlook 0
Similar threads


















































Top