If you understand Outlook’s object model, you can send e-mails and perform other Outlook operations with Visual Basic code. Previously, we examined the object model and looked at some VB code for sending e-mails. Now it’s time to tackle the job of creating notes, tasks, contacts, journal entries, and calendar items.

Creating these items is similar to creating mail items. Outlook’s object model allows creating objects and modifying them as well as modifying the properties of the intrinsic objects that Outlook includes by default.

Outlook’s Notes feature can come in handy, allowing users to create electronic Post-It notes. Listing A shows VB code for creating a note in Outlook.

The Body of the note is what you see when you open it. You can specify different colors for your notes to easily differentiate between them. In our case, the color is green, but it could also be yellow, blue, pink, or white. You must save the note to make sure Outlook keeps it. After you run the code above, Outlook will create a note like that in Figure A.

Figure A
The code in Listing A produced this note.

You can also use VB to create tasks, schedule reminders, assign tasks to others, and specify priority, status, percent done, and other properties. To create and assign a task, you call the Assign method of a TaskItem, as shown in Listing B. You can see how the task will look in Figure B.

Figure B
The code in Listing B will create this task.

As you can see, the task includes the specified subject and body, and the reminder is set for 10:00 A.M. The priority (Importance property of the task object) is High (olImportanceHigh), but you can set it to Normal (olImportanceNormal) or Low (olImportanceLow).

To assign a task, you must add a recipient and use the Assign and Send methods of the task item. For example, the code shown in Listing C assigns the task in our example to user Sam Smith. The resulting task appears in Figure C.

Figure C
We modified the code to assign our sample task.

The system will send an e-mail to notify the person to whom you assigned the task. You can view this message if you go to your Outbox.

Many users store contact information in Outlook for convenience. You can create, modify, and remove contacts in Outlook from Visual Basic. The code in Listing D will create the contact shown in Figure D. Figure E shows the Details tab of this contact item.

Figure D
The code in Listing D will produce this contact item.

Figure E
The Details tab of our sample contact looks like this.

Journal entries
The Outlook Journal is designed to help users keep track of their time. The code in Listing E will create the journal entry shown in Figure F.

Figure F
We created this journal entry with the VB code in Listing E.

Note that the Duration property is measured in minutes. A journal entry can have a number of entry types. In addition to the Conversation type used in our example, you can have the following types:

  • ·        Document
  • ·        E-mail message
  • ·        Fax
  • ·        Letter
  • ·        Meeting
  • ·        Meeting cancellation
  • ·        Meeting request
  • ·        Meeting response
  • ·        Note
  • ·        Phone call remote session
  • ·        Task
  • ·        Task request
  • ·        Task response

Calendar items
Outlook’s Calendar lets you create and store appointments and meetings. Listing F shows an example of code that will create a meeting. The resulting meeting item appears in Figure G.

Figure G
The code in Listing F produced this project meeting item.

The Importance property value can be High, Normal, or Low. The Sensitivity property value can be Private (olPrivate), Personal (olPersonal), Confidential (olConfidential), or Normal (olNormal). You have to call the Send method to invite the attendees to the meeting. Outlook will send messages to all attendees notifying them of the meeting and its location and time.

Under your control
As you can see, you can control nearly every aspect of Outlook from Visual Basic. This gives you tremendous power to integrate Outlook functionality into your enterprise applications. Next time, we’ll look more closely at e-mails, including attachments, folders, and security issues.