![]() |
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?? |
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?? |
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 - |
All times are GMT +1. The time now is 06:43 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com