Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert Excel 2003 spreadsheet into Outlook Contacts table 2003 Stuart[_4_] Excel Discussion (Misc queries) 2 October 6th 08 05:07 PM
Copying Excel 2003 Selection into Outlook 2003 HTML E-Mail Message [email protected] Excel Discussion (Misc queries) 0 July 10th 06 03:07 PM
Excel controlling Outlook Nigel Excel Programming 1 March 31st 05 10:26 AM
Controlling the position of attachments and Body Text in Outlook Richard Buttrey[_4_] Excel Programming 1 November 4th 03 08:27 PM
Controlling Outlook from Excel Using VBA Trevor Shuttleworth Excel Programming 1 September 9th 03 10:43 PM


All times are GMT +1. The time now is 06:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"