• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 34. Advanced Outlook Programming... > Automating Outlook from Other Applic...

Automating Outlook from Other Applications

Outlook has a very powerful and complete object model. This enables you to perform many of the tasks you do every day in Outlook from other applications. You can write Microsoft Word macros that send email to colleagues, use Microsoft Access to send status messages from a database, and even use Visual Basic to create custom applications that do all sorts of things such as email inventory reports to managers and sales representatives. For example, the following code creates an Outlook message, enters recipient information, sets a subject and priority, adds an attachment, and sends the email message:

Sub SendEmail()
    Set objOutlook = CreateObject("Outlook.Application")
    Set objNS = objOutlook.GetNamespace("MAPI")
    Set objInbox = objNS.GetDefaultFolder(olFolderInbox)
    Set objMessage = objInbox.CreateItem(olMailItem)
    objMessage.To = "sally@email.com"
    objMessage.Subject = "Inventory Report for Monday"
    objMessage.Importance = olImportanceHigh
    objMessage.Attachments.Add "c:\Reports\InventoryReport.xls"
    objMessage.Send
    Set objMessage = Nothing
    Set objInbox = Nothing
    Set objNS = Nothing
    Set objOutlook = Nothing
End Sub


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint