' Listing 15.1 A Procedure That Accesses the Outlook Contacts List from Another Application ' Sub AccessOutlookAddressBook() Dim ol As Outlook.Application ' Outlook Automation object Dim ns As Namespace ' Outlook NameSpace object Dim addr As AddressEntry ' Outlook AddressEntry object ' ' Establish a connection and log on to Outlook ' Set ol = CreateObject("Outlook.Application") Set ns = ol.GetNamespace("MAPI") ns.Logon ' ' Grab the first Contacts address ' This is where the Address Book security kicks in ' Set addr = ns.AddressLists("Contacts").AddressEntries(1) ' ' Display the name and address ' MsgBox "The first Contacts entry is " & _ addr.name & " <" & addr.Address & ">" ' ' Log off the session and clear the objects ' ns.Logoff Set addr = Nothing Set ns = Nothing Set ol = Nothing End Sub ' Listing 15.2 A Procedure That Sends an Email Message from Another Application ' Sub SendMessage() Dim ol As Outlook.Application ' Outlook Automation object Dim ns As Namespace ' Outlook NameSpace object Dim mi As MailItem ' Outlook Mailitem object ' ' Establish a connection and log on to Outlook ' Set ol = CreateObject("Outlook.Application") Set ns = ol.GetNamespace("MAPI") ns.Logon ' ' Create a new message ' Set mi = ol.CreateItem(olMailItem) ' ' Add a recipient without using Contacts ' mi.To = "blah@yadda.com" mi.Subject = "Just Testing" ' ' Send it ' This is where the Send security kicks in ' mi.Send ' ' Log off the session ' ns.Logoff Set mi = Nothing Set ns = Nothing Set ol = Nothing End Sub