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 and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

sending selected email as attachment in new email



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old January 11th 07, 12:16 PM posted to microsoft.public.outlook.program_vba
draco
external usenet poster
 
Posts: 2
Default sending selected email as attachment in new email

Hi

I'm writing a macro in Outlook, and part of the functionality is to
reference the currently selected mail and to send it as an attachment
in another mail.

I know this functionality exists in Outlook, so it should be possible
to reproduce it in a macro.

So I have my function that sets up a mail:

'send mail
Dim objMail As Outlook.MailItem
Set objMail = ThisOutlookSession.CreateItem(olMailItem)
objMail.To = ...
objMail.Attachments.Add (GetSelectedMail)
objMail.Send

I'm not sure about that Attachments.Add function - it should specify
the parameter is a reference type rather than a file path but I'm not
sure how.

And here is the function to get the attachment:

Private Function GetSelectedMail() As Outlook.MailItem

Dim objSelection As Outlook.Selection
Set objSelection = ThisOutlookSession.ActiveExplorer.Selection
Dim objMailItem As Outlook.MailItem
If objSelection.Count = 0 Then
objMailItem = Nothing
Else
objMailItem = objSelection.Item(1)
End If
GetSelectedMail = objMailItem

End Function

This is not working. I get an error at this line:
objMailItem = objSelection.Item(1)
...object variable or with block variable not set...

Any ideas??

Ads
  #2  
Old January 11th 07, 03:56 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default sending selected email as attachment in new email

Set objMailItem = objSelection.Item(1)

But I'd check for the Class of the selection item in case it's not an email
item (it could be a task request, a meeting request, etc.).

Also, I'd check for objSelection Is Nothing to make sure something is
selected.

Use objMail.Attachments.Add (GetSelectedMail, olByReference) to add an item
by reference.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"draco" wrote in message
oups.com...
Hi

I'm writing a macro in Outlook, and part of the functionality is to
reference the currently selected mail and to send it as an attachment
in another mail.

I know this functionality exists in Outlook, so it should be possible
to reproduce it in a macro.

So I have my function that sets up a mail:

'send mail
Dim objMail As Outlook.MailItem
Set objMail = ThisOutlookSession.CreateItem(olMailItem)
objMail.To = ...
objMail.Attachments.Add (GetSelectedMail)
objMail.Send

I'm not sure about that Attachments.Add function - it should specify
the parameter is a reference type rather than a file path but I'm not
sure how.

And here is the function to get the attachment:

Private Function GetSelectedMail() As Outlook.MailItem

Dim objSelection As Outlook.Selection
Set objSelection = ThisOutlookSession.ActiveExplorer.Selection
Dim objMailItem As Outlook.MailItem
If objSelection.Count = 0 Then
objMailItem = Nothing
Else
objMailItem = objSelection.Item(1)
End If
GetSelectedMail = objMailItem

End Function

This is not working. I get an error at this line:
objMailItem = objSelection.Item(1)
...object variable or with block variable not set...

Any ideas??


  #3  
Old January 29th 07, 02:20 PM posted to microsoft.public.outlook.program_vba
draco
external usenet poster
 
Posts: 2
Default sending selected email as attachment in new email



I managed to work out the first part by myself, but the extra tests
you proposed were very useful. Thanks very much.

On Jan 11, 3:56 pm, "Ken Slovak - [MVP - Outlook]"
wrote:
Set objMailItem = objSelection.Item(1)

But I'd check for the Class of the selection item in case it's not an email
item (it could be a task request, a meeting request, etc.).

Also, I'd check for objSelection Is Nothing to make sure something is
selected.

Use objMail.Attachments.Add (GetSelectedMail, olByReference) to add an item
by reference.

--
Ken Slovak
[MVP - Outlook]http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Optionshttp://www.slovaktech.com/products.htm

"draco" wrote in ooglegroups.com...



Hi


I'm writing a macro in Outlook, and part of the functionality is to
reference the currently selected mail and to send it as an attachment
in another mail.


I know this functionality exists in Outlook, so it should be possible
to reproduce it in a macro.


So I have my function that sets up a mail:


'send mail
Dim objMail As Outlook.MailItem
Set objMail = ThisOutlookSession.CreateItem(olMailItem)
objMail.To = ...
objMail.Attachments.Add (GetSelectedMail)
objMail.Send


I'm not sure about that Attachments.Add function - it should specify
the parameter is a reference type rather than a file path but I'm not
sure how.


And here is the function to get the attachment:


Private Function GetSelectedMail() As Outlook.MailItem


Dim objSelection As Outlook.Selection
Set objSelection = ThisOutlookSession.ActiveExplorer.Selection
Dim objMailItem As Outlook.MailItem
If objSelection.Count = 0 Then
objMailItem = Nothing
Else
objMailItem = objSelection.Item(1)
End If
GetSelectedMail = objMailItem


End Function


This is not working. I get an error at this line:
objMailItem = objSelection.Item(1)
...object variable or with block variable not set...


Any ideas??- Hide quoted text -- Show quoted text -


 




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
Auto display of selected incoming email fails Richard Lewis Haggard Outlook - General Queries 1 October 13th 06 08:30 PM
Email Created for a Past Account instead to selected address C Emmons Outlook - Calandaring 2 September 21st 06 02:43 PM
sending email with attachment results in multiple copies being received Mick Ruthven Outlook Express 9 July 12th 06 02:51 AM
Sending email with attachment produces error message but email is OW Outlook Express 3 June 24th 06 09:59 PM
my outlook email now comes in big text with normal 12 pt selected chasflies Outlook - Installation 1 January 30th 06 11:01 PM


All times are GMT +1. The time now is 05:09 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.