ID: Q181202
The information in this article applies to:
This article provides an overview of programming Microsoft Outlook 98 using Automation from another program.
Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures. Microsoft Support professionals can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific needs. If you have limited programming experience, you may want to contact the Microsoft fee-based consulting line at (800) 936-5200. For more information about the support options available from Microsoft, please see the following page on the World Wide Web:
   http://www.microsoft.com/support/supportnet/refguide/default.asp
You can use either "early" or "late" binding to start an Automation session. Late binding uses either the GetObject or CreateObject function to initialize Outlook. For example, the following code sets an object to the Outlook program, which is the highest level object in the Outlook object model. All Automation code must first define an Outlook.Application object in order to access any of the other Outlook objects below that.
   Dim objOL as Object
   Set objOL = CreateObject("Outlook.Application")
1. In the Visual Basic Editor, click References on the Tools menu.
2. Click to select the "Microsoft Outlook 8.5 Object Library" check box,
   and then click OK.
Once you reference the Outlook object library, you can use the following syntax to start an Outlook session:
   Set ol = New Outlook.Application
The Outlook object model provides functionality to manipulate data stored in Outlook folders. However, there is limited functionality available to control Outlook itself. For example, you cannot use the object model to change the Options settings on the Tools menu.
NOTE: As a possible workaround to limitations regarding the object model, you can use the CommandBars object provided by Microsoft Office to execute commands that are assigned to either toolbar buttons or menu commands. For example, you can use the CommandBars object to execute the New Call command (on the Dial submenu of the Tools menu) to bring up the New Call dialog box.
For more information about using CommandsBars with Microsoft Outlook 98, please see the following article in the Microsoft Knowledge Base:
   Article-ID: Q182394
   Title     : OL98: How to Use Command Bars in Outlook Solutions
   Set ol = New Outlook.Application
   Set olns = ol.GetNamespace("MAPI")
   Set ol = New Outlook.Application
   Set olns = ol.GetNamespace("MAPI")
   Set objFolder = olns.GetDefaultFolder(olFolderContacts)
   Article-ID: Q182614
   Title     : OL98: Programming Examples for Referencing Items and Folders
Create a New Default Task Item:
   Sub CreateNewDefaultOutlookTask()
      Dim ol As Object
      Dim NewTask As Object
      ' Set the Application object.
      Set ol = New Outlook.Application
      ' You can only use CreateItem for default items.
      ' Vbaoutl.hlp lists other Outlook constants to create other items.
      Set NewTask = ol.CreateItem(olTaskItem)
      ' Display the new task form so the user can fill it out.
      NewTask.Display
   End Sub
   Sub CreateNewContactFromCustomForm()
      Dim ol As Object
      Dim olns As Object
      Dim objFolder As Object
      Dim AllContacts As Object
      Dim NewContact As Object
      ' Set the Application object.
      Set ol = New Outlook.Application
      ' Set the Namespace object.
      Set olns = ol.GetNamespace("MAPI")
      ' Set the default Contacts folder.
      Set objFolder = olns.GetDefaultFolder(olFolderContacts)
      ' Set objAllContacts equal to the collection of all contacts.
      Set AllContacts = objFolder.Items
      ' Add a new contact to the AllContacts collection using the
      ' "IPM.Contact.MyForm" form.
      Set NewContact = AllContacts.Add("IPM.Contact.MyForm")
      ' Display the new contact form.
      NewContact.Display
   End Sub
   Sub GetOutlookContacts()
      Dim ol As Object
      Dim olns As Object
      Dim objFolder As Object
      Dim objAllContacts As Object
      Dim Contact As Object
      ' Set the Application object.
      Set ol = New Outlook.Application
      ' Set the Namespace object.
      Set olns = ol.GetNamespace("MAPI")
      ' Set the default Contacts folder.
      Set objFolder = olns.GetDefaultFolder(olFolderContacts)
      ' Set objAllContacts equal to the collection of all contacts.
      Set objAllContacts = objFolder.Items
      ' Loop through each contact.
      For Each Contact In objAllContacts
         ' Display the Fullname field for the contact.
         MsgBox Contact.FullName
      Next
   End Sub
The following list includes some important resources for automating Outlook, located on the Microsoft Outlook Developer Forum:
      http://www.microsoft.com/OfficeDev/Articles/Opg/005/005.htm
      http://www.microsoft.com/OutlookDev/Articles/outprog.htm
For more information about creating solutions with Microsoft Outlook 98, please see the following articles in the Microsoft Knowledge Base:
   Article-ID: Q180826
   Title     : OL98: Resources for Custom Forms and Programming
   Article-ID: Q182349
   Title     : OL98: Questions About Custom Forms and Outlook Solutions
Keywords          : kbdta kbdtacode OffVBS 
Version           : WINDOWS:
Platform          : WINDOWS
Issue type        : kbhowtoLast Reviewed: May 17, 1999