Automating Outlook 98 VB Help

Incorporating e-mail capabilities into Desktop applications is becoming increasingly popular in today’s software. To make your applications e-mail-aware, you can ,use the .MAP! control or program Outlook’s objects. We are going to discuss how to mail enable your Visual Basic applications through the Outlook VBA because Outlook is simple, manages fore types of information than just messages, and it’s it very practical tool for carrying out day-to-day operations. Many corporations use Outlook to automate common tasks like appointment scheduling and routing e-mail. Because of the variety of tasks that can be performed from within Outlook’s environment, you should learn the basics of programming its objects. Areas Excel and Office can be programmed with VBA, Outlook can only be programmed with Visual Basic Script. However, you can use VBA to automate Outlook.

To contact Outlook and program the objects it exposes, you must first create an object variable, such as the OLApp variable:

Unlike Word and Excel, Outlook 98 doesn’t expose a single object like a Document or Worksheet that gives you access to the information it can handle. Outlook 98 contains several objects including mail messages, contacts, and tasks. The most likely candidate to use as the basic unit of information in Outlook is a folder. Depending” on the operation you want to perform with Outlook, you must first select the appropriate folder in the Shortcuts bar. For example, to-view the incoming e-mail messages, you must select the Inbox folder; to add a contact, you must first select the Contacts folder. You can’t expect the find information about your contacts in the Inbox folder or the pending messages in the Calendar folder. Since every operation in Outlook is initiated with the Selection of the proper folder, the various folders of the application are the top-level objects.

To access the folder objects, you must create a MAPI message store. A MAPI message store is a data source that provides all types of information that can be stored by ” Outlook. If you’ve used Outlook before, You know that it’s essentially a front end for a database that can store many different types of information. To access this information, you must create a mNameSpace object variable with the following statement:

Set mNameSpace – OLApp.GetNamespace(“MAPr”)

The necessary code for accessing the information stored by Outlook is shown next:

Through the mNameSpace variable you can access the various folders of Outlook. The method for accessing a folder is the GetDefaultFolder method, which “accepts the name of the folder as argument and returns an object variable. The object variable returned ByGetDefaultFolder method. provides properties and methods that give your application access to the items stored in the folder .

The various folders maintained by Outlook can be accessed with the following constants (their names are self-explanatory):

To retrieve all the items in the Contacts folder, use the following statement:

The Items property returns a collection that contains all the items in the specified folder.

Each folder contains different types of information. The Contacts folder is made up of Contactltem objects, the InBox and OutBox folders contain MailItem objects, and the Calendar folder contains a collection of Appointmentltem objects. Each one of these objects provides numerous properties, which are the attributes of the item it represents. For example, a Contactltem object provides properties for setting just about any attribute of a contact.

To see the properties of the ContactItem object, open the Object Browser, select Outlook in the Class box, and in the Classes list click the Contactltem entry, as shown.The members of the selected Class will appear in the right pane. The properties you’ll use most often in your applications are LastName, First- Name, EmaillAddress, Title, and the properties that begin with Home.Address and BusinessAddress. These are the fields you can set in the Contact dialog box when you add or edit Contact with Outlook. If you need additional fields, you can create your own custom properties. The custom properties are also accessed by name, but I’m not going to discuss them here. You should see Outlook’s Help files for more information on adding custom properties.

A property that’s common to all items is the EntryID property, which is a Long value that uniquely identifies each item. Entrylf) values are similar to IDs you assign to the various records in a database (they identify the record, but they have no other apparent meaning). Of course, you can’t have the user select a contact or message based on its EntryID (it makes much more sense to present a list of names
or companies to select from) but you can use them to bookmark items. If you populate the nodes of a TreeView control with the messages or.contacts stored in Outlook, you can use the EntryID fields as keys for their nodes. This way, the user can select items based on more meaningful information, such as’name, company, or message subject. Then, you can instantly locate the desired item in the corresponding folder by its ID. You’ll see how the EntryID property is used in the examples of the following sections.

Posted on November 6, 2015 in OLE Automation and VBA

Share the Story

Back to Top
Share This