![]() |
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. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
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
|
|||
|
|||
![]()
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
|
|||
|
|||
![]() 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 |
Display Modes | |
|
|
![]() |
||||
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 |