Starting an Outlook Automation Session

Outlook Developer Reference
Starting an Outlook Automation Session

Because Microsoft Outlook supports automation, you can control Outlook from any program written with Microsoft Visual Basic for Applications (VBA), Microsoft Visual Basic.NET, or Microsoft C#. Automation provides a standard method for one application to access the objects, methods, properties, and events of other applications that support automation.

The Outlook object model provides all of the functionality necessary to manipulate data stored in Outlook folders. Outlook stores all of its information in Messaging Application Programming Interface (MAPI) folders. You obtain Business Contact Manager for Outlook objects by instantiating Outlook objects.

To start an Outlook automation session, do the following:

  1. Instantiate an Outlook Application object, which is the highest-level object in the Outlook object model. All automation code must first define an Outlook Application object to be able to access any other Outlook objects.
    Outlook.ApplicationClass _app = new Outlook.ApplicationClass();
    Outlook.Application olApp = (Outlook.Application) _app;
    Dim objOL as Outlook.Application
    Set olApp = CreateObject("Outlook.Application")
  2. Set a Namespace object to refer to MAPI folder.
    Outlook.NameSpace olNameSpace = _app.GetNamespace("MAPI");
    Dim objNS As Outlook.NameSpace
    Set objNS = olApp.GetNamespace("MAPI")
  3. Set an object variable to reference the folder that contains the items you will use.
    Outlook.Folders folders = olNameSpace.Session.Folders;
    Outlook.Folder bcmRootFolder = (Outlook.Folder)folders["Business Contact Manager"]; 
    Dim olFolders As Outlook.Folders
    Dim bcmRootFolder As Outlook.Folder

Set olFolders = objNS.Session.Folders Set bcmRootFolder = olFolders("Business Contact Manager")

The preceding code examples combine to form the correct reference to the Business Contact Manager root folder. You can then navigate to the following sub-folders objects:

See Also

Welcome to the Business Contact Manager for Outlook Developer Guide | Automating Business Contact Manager From a .NET Framework Application | Automating Business Contact Manager From a VBA Application | Office Developer Center: Outlook 2007