Create Task from Email and put body & email as attachment into task notes

Status
Not open for further replies.

azhumvee

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
Using Outlook 2010... So as far as converting emails to tasks.. outlook only has option to move or copy an email with Text **OR** Attachment, but I want both. Is this possible with a macro? - sorry, day 1 of macros here :(

I still want the subject of the email carried over as the temporary Subject of the task (and leaving the cursor there to make changes to it)

Next, would it be possible to then (after creating the associated task) - also perform a particular Quick Step (by name of the quick step) ? I just want to be able to move the email to a folder out of the inbox, and maybe toss a category on it too...

So I have Developer in my ribbon.. i click on macros.. name one, create it.. i now have VBA with a Sub macroname()

End Sub


after I paste the code, I'll hit debug - Project1 ? Hope i'm on the right track. Thank you so much everyone. You are all amazing from what I've seen posted here.. TIA!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I have a run a script sample at http://www.slipstick.com/outlook/rules/create-task-email-rule/ - you can set the task subject to be the mail subject but the cursor isn't left in the subject field. It can be converted to a macro you run on demand, there is a sample macro at the bottom of the page.

Michael will correct me if i'm wrong, but as far as I know, quick steps are not available to be automated, so you can't call one from a macro. You could build the same steps into a macro. Adding a category to the original email and moving it is not a big deal.

See http://www.slipstick.com/developer/how-to-use-outlooks-vba-editor/ for basics on using the editor, but yeah, that is basically what you do.
 

azhumvee

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
Michael - thank you, i'm aware of the follow-up feature.. i just don't like the fact the flags/follow-ups don't appear in any mobile form of outlook access.. and the main reason i dont want to use those - i cant have the fields that exist only in tasks (notes, % complete etc.)

Diane - thanks.. would it indeed be possible to do both though thru a macro/vba? that is - Move an email to create a new task with attachment and text of the message? Ideally I would want to select an entire existing email conversation (top level of hierarchy) and push a macro button and have it move all the emails as separate attachments and include the full summary of all the text in the notes section of a new task.. essentially clearing my inbox of that conversation, and then i work with it (and reply as needed) strictly from a task view... hope this makes sense

I will have to find someone to code this for me. :( however, i did successfully implement and use the code from the sample macro at the bottom of your create-task-email-rule page... its just a start of what i want to build. :)

do you know of anyone on these forums that would take $ or a donation to build little GTDish macro codes for me?
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
That's possible with a macro except there's no selection if you just select the header of the conversation.

If you have usual $$/hour in mind when you think of "donation", I could help you.
 

azhumvee

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
Thank you.. Well as it turned out i've muddled up the concept of what I was trying to do.. one small problem.. I wanted the embedded email to be ABOVE the body in the task notes area... i'm thinking thats impossible.. am I right? heres the code

Sub MoveSelectedMailtoTask()
Dim objTask As Outlook.TaskItem
Dim objMail As Outlook.MailItem

Set objTask = Application.CreateItem(olTaskItem)

For Each objMail In Application.ActiveExplorer.Selection

With objTask
.Subject = objMail.Subject
.StartDate = objMail.ReceivedTime
.Body = vbCrLf + vbCrLf + objMail.Body
objMail.SaveAs attPath & objMail.EntryID
objTask.Attachments.Add attPath & objMail.EntryID, olEmbeddeditem
Kill (attPath & objMail.EntryID)
.Display
End With
objMail.Delete
Next
Set objTask = Nothing
Set objMail = Nothing
End Sub
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Attachments.Add has more paramters, one is for the position.
 

azhumvee

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
I put
objTask.Attachments.Add attPath & objMail.EntryID, olEmbeddeditem, 1

and it basically ignores the position.. still puts it at after the body..
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Despite the description mentioned by Diane, it does work here for task items in Outlook 2007, and 2010. I canot tell you why it shouldn't work for you.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I see the same thing as azhumvee, using Outlook 2013. While it should work for Tasks because they are rich text, it's not working for me.
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
I didn't try it but maybe it's due to the very long EntryID file name?
 

azhumvee

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
Michael, I'll try that theory when I get home.. didn't want to start a new thread but I have a similar section of vba code and I want this to behave a little differently.. But I'm having problems of course... i want this one to take an email i have selected, move it to a prespecified folder (test folder below the inbox in this example).. then create a task with body of email & embedded original email .. ignoring the position of the embedded item for now.. for whatever reason I get a "the operation failed" message.. I'm assuming it's because the EntryID changes when email is moved to a different folder.. is there a way to have my code below first move it, get the entryID of the new location, THEN create a task all in one macro? code as follows:


Sub MoveToFiled()
Dim ns As Outlook.NameSpace
Dim moveToFolder As Outlook.MAPIFolder
Dim objItem As Outlook.MailItem
Dim objTask As Outlook.TaskItem
Dim objMail As Outlook.MailItem

Set ns = Application.GetNamespace("MAPI")
'Define path to the target folder
Set moveToFolder = ns.GetDefaultFolder(olFolderInbox).Folders("test")
If Application.ActiveExplorer.Selection.Count = 0 Then
MsgBox ("No item selected")
Exit Sub
End If
If moveToFolder Is Nothing Then
MsgBox "Target folder not found!", vbOKOnly + vbExclamation, "Move Macro Error"
End If
'For Each objItem In
Set objItem = Application.ActiveExplorer.Selection(1)
If moveToFolder.DefaultItemType = olMailItem Then
If objItem.Class = olMail Then
objItem.Move moveToFolder
Else
MsgBox "wrong type of item"
Exit Sub
End If
End If
'Next
Set objTask = Application.CreateItem(olTaskItem)
'For Each objMail In Application.ActiveExplorer.Selection
With objTask
.subject = objItem.subject
.StartDate = objItem.ReceivedTime
.Body = vbCrLf & vbCrLf & "url:eek:utlook:" & objItem.EntryID & vbCrLf + objItem.Body
objItem.SaveAs attPath & objItem.EntryID
objTask.Attachments.Add attPath & objItem.EntryID, olEmbeddeditem
Kill (attPath & objItem.EntryID)
.Display
End With
'objMail.Delete
'Next
Set objItem = Nothing
Set moveToFolder = Nothing
Set ns = Nothing
Set objTask = Nothing
Set objMail = Nothing
End Sub
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
The Move function returns the new, moved item. Set the variable to it, then the new EntryID will be available.
 

azhumvee

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
Thanks Michael.. wow i actually figured it out on my own.. :)

last question (I think!) for this topic... can I make the url outlook entry id link have a name so it doesnt have to show a 80 to 100 or whatever character link to the entryID? but instead just an alias/name for the link? like a clickable "Original Message"
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Really on your own? If our suggestions are wrong, and you've found another solution, post it so others can benefit.

For the url the message must be in html format. See in an html documentation how to use the <a> tag.
 

azhumvee

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server 2010
no, misunderstanding on the "figured it out on my own".. I'm week 2 into vba so your input on the move function left me clueless on what & where to put the move code. but i trial'd and error'd it until i got it. thats what i meant by on my own.. it was your solution :)

ok i'll try the html formatting but the test emails i've used always come out ugly (lots of formatting garbage). i'll read up.. thx again
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Yep, formatting is an issue. Even MS cannot do that reliably. However, plain text doesn't support what you want.
 
Status
Not open for further replies.
Top