Microsoft Office Tutorials and References
In Depth Information
Using Your Address Book
Your macro code can also get email addresses from the address book. You see an example of this
in Chapter 25 when I present a VBA application that sends a message to all contacts in a
specified address book.
MyMailMessage.Save
With MyMailMessage.Attachments
.Add “c:\data\TechnologyWhitePaper.doc”, olByValue, , _
“White Paper”
.Add “c:\data\MedicalExpenses.xls”
End With
Completing and Sending a Message
Other than addressing an email message, a message needs a subject line and a body. The subject is
set by assigning text to the MailItem.Subject property.
The body is not quite so simple because you have the option of sending a plain text format
message, a Rich Text Format (RTF) message, or an HTML format message. When you create a new
MailItem object, the format is set to the default message format as specified in Outlook’s mail
options (refer to Chapter 5 for more information). To change the format for an individual message,
set the MailItem.BodyFormat property to one of these constants: olFormatHTML ,
olFormatPlain , or olFormatRichText .
You assign the actual body of the message to either the Body property or the HTMLBody property
depending on whether or not the text includes HTML formatting tags. Of course, the HTMLBody
property is irrelevant for a plain text format message.
Finally, call the MailItem.Send() method to send the message.
Programming Calendar Items
The first thing you must do to work programmatically with calendar items is to get a reference to the
Calendar folder. Because this is one of Outlook’s default folders, you obtain this reference using the
GetDefaultFolder() method just like you learned earlier in this chapter for the Inbox folder:
Dim MAPINameSpace As Outlook.NameSpace
Dim CalendarFolder As Outlook.Folder
Set MAPINameSpace = GetNameSpace(“MAPI”)
Set CalendarFolder = _
MAPINameSpace.GetDefaultFolder(olFolderCalendar)
Search JabSto ::




Custom Search