![]() |
Controlling Outlook 2003 with excel
I found this code on the internet which would be very helpful, problem is in the first line. I don't know what it means to have a referance to Outlook 8.0 in the object library. I must not have that because it doesn't work. I've made the highlighted error area red. How do I set this macro up to work with Outlook 2003? ' requires a reference to the Microsoft Outlook 8.0 Object Library Sub SendAnEmailWithOutlook() ' creates and sends a new e-mail message with Outlook Dim OLF As Outlook.MAPIFolder, olMailItem As Outlook.MailItem Dim ToContact As Outlook.Recipient Set OLF = GetObject("", _ "Outlook.Application").GetNamespace("MAPI").GetDef aultFolder(olFolderInbox) Set olMailItem = OLF.Items.Add ' creates a new e-mail message With olMailItem ..Subject = "Subject for the new e-mail message" ' message subject Set ToContact = ") ' add a recipient Set ToContact = ") ' add a recipient ToContact.Type = olCC ' set latest recipient as CC Set ToContact = ") ' add a recipient ToContact.Type = olBCC ' set latest recipient as BCC ..Body = "This is the message text" & Chr(13) ' the message text with a line break ..Attachments.Add "C:\FolderName\Filename.txt", olByValue, , _ "Attachment" ' insert attachment ' .Attachments.Add "C:\FolderName\Filename.txt", olByReference, , _ "Shortcut to Attachment" ' insert shortcut ' .Attachments.Add "C:\FolderName\Filename.txt", olEmbeddedItem, , _ "Embedded Attachment" ' embedded attachment ' .Attachments.Add "C:\FolderName\Filename.txt", olOLE, , _ "OLE Attachment" ' OLE attachment ..OriginatorDeliveryReportRequested = True ' delivery confirmation ..ReadReceiptRequested = True ' read confirmation '.Save ' saves the message for later editing ..Send ' sends the e-mail message (puts it in the Outbox) End With Set ToContact = Nothing Set olMailItem = Nothing Set OLF = Nothing End Sub -- wilro85 ------------------------------------------------------------------------ wilro85's Profile: http://www.excelforum.com/member.php...o&userid=26935 View this thread: http://www.excelforum.com/showthread...hreadid=557145 |
Controlling Outlook 2003 with excel
Hi Wilro,
In the VBE, Tools | References | scroll to and check the reference to the Microsoft Oulook Object Library. Incidentaaly, an excellent source for Excel/Outlook code is Ron de Bruin's site: http://www.rondebruin.nl/sendmail.htm --- Regards, Norman "wilro85" wrote in message ... I found this code on the internet which would be very helpful, problem is in the first line. I don't know what it means to have a referance to Outlook 8.0 in the object library. I must not have that because it doesn't work. I've made the highlighted error area red. How do I set this macro up to work with Outlook 2003? ' requires a reference to the Microsoft Outlook 8.0 Object Library Sub SendAnEmailWithOutlook() ' creates and sends a new e-mail message with Outlook Dim OLF As Outlook.MAPIFolder, olMailItem As Outlook.MailItem Dim ToContact As Outlook.Recipient Set OLF = GetObject("", _ "Outlook.Application").GetNamespace("MAPI").GetDef aultFolder(olFolderInbox) Set olMailItem = OLF.Items.Add ' creates a new e-mail message With olMailItem Subject = "Subject for the new e-mail message" ' message subject Set ToContact = ") ' add a recipient Set ToContact = ") ' add a recipient ToContact.Type = olCC ' set latest recipient as CC Set ToContact = ") ' add a recipient ToContact.Type = olBCC ' set latest recipient as BCC Body = "This is the message text" & Chr(13) ' the message text with a line break Attachments.Add "C:\FolderName\Filename.txt", olByValue, , _ "Attachment" ' insert attachment ' .Attachments.Add "C:\FolderName\Filename.txt", olByReference, , _ "Shortcut to Attachment" ' insert shortcut ' .Attachments.Add "C:\FolderName\Filename.txt", olEmbeddedItem, , _ "Embedded Attachment" ' embedded attachment ' .Attachments.Add "C:\FolderName\Filename.txt", olOLE, , _ "OLE Attachment" ' OLE attachment OriginatorDeliveryReportRequested = True ' delivery confirmation ReadReceiptRequested = True ' read confirmation '.Save ' saves the message for later editing Send ' sends the e-mail message (puts it in the Outbox) End With Set ToContact = Nothing Set olMailItem = Nothing Set OLF = Nothing End Sub -- wilro85 ------------------------------------------------------------------------ wilro85's Profile: http://www.excelforum.com/member.php...o&userid=26935 View this thread: http://www.excelforum.com/showthread...hreadid=557145 |
All times are GMT +1. The time now is 05:04 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com