Controlling Outlook 2003 with excel

W

wilro85

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").GetDefaultFolder(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 = .Recipients.Add("(e-mail address removed)") ' add a
recipient
Set ToContact = .Recipients.Add("(e-mail address removed)") ' add a
recipient
ToContact.Type = olCC ' set latest recipient as CC
Set ToContact = .Recipients.Add("(e-mail address removed)") ' 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top