A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook - General Queries
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Outlook VBA -- Insert Email reference into new Task



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old July 18th 07, 05:29 PM posted to microsoft.public.outlook
Steve Newhouse
external usenet poster
 
Posts: 2
Default Outlook VBA -- Insert Email reference into new Task

Hi guys,

I've written a script that creates a task from a selected email. It
puts the body of the email into the body of the task, but I also
wanted it to include a "reference" to the original email (like that
message icon perhaps) so I can link back to it. Anyone know how to do
this?

Here's the code:

-----------

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
Dim userName As String

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

With olTsk
.Subject = item.Subject
.Status = olTaskNotStarted

'Need to insert reference to the original email in the new
task so I can link back to it
' ".Body = item" ' didn't work, neither did
".Attachments.Add item"

'Remove formatting
item.BodyFormat = olFormatPlain
.Body = Replace(item.Body, " " & vbCrLf, vbCr)

.Save

End With

Set olTsk = Nothing
Set olApp = Nothing

End Sub

-----------

P.S. -- You can see that I am removing formatting and attempting to
remove extra line breaks. This is because I was getting all kinds of
extra line breaks when copying the body from the email to the task.
Any way to keep the formatting but lose extra line breaks?

Ads
  #2  
Old July 18th 07, 05:36 PM posted to microsoft.public.outlook
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default Outlook VBA -- Insert Email reference into new Task

Use the TaskItem.Attachments.Add method using olEmbeddedItem for the Type parameter.

FYI, there is a newsgroup specifically for general Outlook programming issues "down the hall" at microsoft.public.outlook.program_vba or, via web interface, at http://www.microsoft.com/office/comm....program_v ba
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Steve Newhouse" wrote in message oups.com...
Hi guys,

I've written a script that creates a task from a selected email. It
puts the body of the email into the body of the task, but I also
wanted it to include a "reference" to the original email (like that
message icon perhaps) so I can link back to it. Anyone know how to do
this?

Here's the code:

-----------

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
Dim userName As String

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

With olTsk
.Subject = item.Subject
.Status = olTaskNotStarted

'Need to insert reference to the original email in the new
task so I can link back to it
' ".Body = item" ' didn't work, neither did
".Attachments.Add item"

'Remove formatting
item.BodyFormat = olFormatPlain
.Body = Replace(item.Body, " " & vbCrLf, vbCr)

.Save

End With

Set olTsk = Nothing
Set olApp = Nothing

End Sub

-----------

P.S. -- You can see that I am removing formatting and attempting to
remove extra line breaks. This is because I was getting all kinds of
extra line breaks when copying the body from the email to the task.
Any way to keep the formatting but lose extra line breaks?

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Outlook 2007 Task Form Insert Ribbon (Attach Group) [email protected] Outlook - General Queries 9 April 26th 07 07:38 PM
Can I insert tabs or change margin in my Task-Microsoft Outlook? [email protected] Outlook - General Queries 1 December 15th 06 12:07 AM
insert as text (to insert html into email body) Iona Outlook - General Queries 1 July 13th 06 12:10 PM
Cannot Insert Item into a task occasionally - Outlook 2003 [email protected] Outlook - General Queries 1 May 10th 06 04:47 AM
How do I insert a clipart item in task reminders? Sue Mosher [MVP-Outlook] Outlook - Using Forms 0 February 6th 06 08:12 PM


All times are GMT +1. The time now is 09:29 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.