The information in this article applies to:
SUMMARY
This article provides an overview of programming Outlook using
Automation from another program. The following topics are covered: MORE INFORMATIONMicrosoft 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 a Microsoft Certified Solution Provider
or the Microsoft fee-based consulting line at (800) 936-5200. For more information about
Microsoft Certified Solution Providers, please see the following page on the World Wide Web:
http://www.microsoft.com/mcsp/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/overview/overview.aspAutomation allows one program to control another program by either issuing commands or retrieving information programmatically. You can use the code examples in this article in Microsoft Word, Microsoft Excel, Microsoft Visual Basic, or any other program that supports Automation. Early vs. Late BindingYou 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.
To use early binding, you first need to reference the available Outlook
object library. To do this from Visual Basic (VB) or Visual Basic for
Applications, follow these steps:
Using early binding has two important advantages. First, code using early
binding runs faster than code using late binding (CreateObject/GetObject).
Second, because you reference the Outlook object library, you can get
online Outlook programming help using the object browser and Help system.
The Outlook Object ModelThe Outlook object model allows you to manipulate data stored in Outlook folders. New features in Outlook also allow you to manipulate the Outlook Bar, work with selected items in a folder, and manipulate both item-level and application-level windows. By adding events, your code can respond to many things that occur in Outlook, allowing you to create an event-driven solution.However, you will find that compared to Word and Excel, there is limited functionality available to control Outlook itself. Many features of Outlook are not exposed or customizable through the Outlook object model. For example, you cannot use the object model to change the Options settings on the Tools menu, although a new feature in Outlook is that you can can create your own page in the Options, or Folder Properties dialog box. NOTE: As a possible workaround to limitations regarding the object model, you can use the CommandBars object provided by Microsoft Office to execute most commands that are assigned to either toolbar buttons or menu commands. For example, you can use the CommandBars object to run the New Call command, on the Dial submenu of the Tools menu, to bring up the New Call dialog box. For additional information about using CommandsBars with Outlook, please see the following article in the Microsoft Knowledge Base: Q201096 OL2000: How to Use Command Bars in Outlook SolutionsMost programming solutions need to interact with the data stored in Outlook. Outlook stores all of its information in Messaging Application Programming Interface (MAPI) folders. Therefore, after you set an object variable to Outlook.Application, you will commonly set a Namespace object to MAPI:
Once you set the Namespace object, you are ready to set the next object to
a folder within the MAPI Namespace. One common way of doing this is by
specifying the Outlook default folders, which are the folders at the same
folder level as the Inbox that receives incoming e-mail. The following code
will set the objFolder object to the default Contacts folder:
For additional information about referencing other types of folders,
please see the following article in the Microsoft Knowledge Base:Q208520 OL2000: Programming Examples for Referencing Items and FoldersOnce you are programmatically at the folder that contains the items you want to either use or create, you can use appropriate code to accomplish your programming task. See the examples later in the article for some common programming examples. In addition to accessing Outlook data from another application, you can also have your application become aware of when certain events occur in Outlook. Examples of events are when an item is added to a folder, when the user selects a different item in the folder, or when an Outlook reminder is displayed. For a complete list of available events, see the Microsoft Outlook Visual Basic Reference (Vbaoutl9.chm). For information on obtaining the help file, see the References section in this article. For an example of how you can integrate Outlook events in your application, please see the following article in the Microsoft Knowledge Base: Q225502 OL2000: Example of Using Outlook Events in Another Program Sample Code for Common Programming TasksExample: Create a New Default Task Item
Example: Create a New Contact Using a Custom Form
Example: Loop Through All the Default Contacts
REFERENCES
For additional information about available resources and answers
to commonly asked questions about Microsoft Outlook 2000 solutions,
please see the following article in the Microsoft Knowledge Base: Q146636 OL2000: Questions About Custom Forms and Outlook Solutions Additional query words: OutSol OutSol2000 OL2K
Keywords : kbdta kbdtacode OffVBS |
Last Reviewed: November 13, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |