Tài liệu Module 7: Working with the Microsoft Outlook 2000 Object Model - Pdf 84


Contents
Overview 1
Using the Application Object 2
Using the NameSpace Object 11
Using the MAPIFolder Object 19
Working with Outlook 2000 Items
Programmatically 28
Using the Explorer Object 40
Using the Inspector Object 51
Working with the Outlook Bar 57
Lab A: Creating Address Labels by
Using the Word Object Model 65
Lab B: Adding an Outlook Bar Group
and Outlook Bar Shortcuts 69
Review 73

Module 7: Working with the
Microsoft Outlook 2000
Object Model Information in this document is subject to change without notice. The names of companies,
products, people, characters, and/or data mentioned herein are fictitious and are in no way intended
to represent any real individual, company, product, or event, unless otherwise noted. Complying
with all applicable copyright laws is the responsibility of the user. No part of this document may
be reproduced or transmitted in any form or by any means, electronic or mechanical, for any
purpose, without the express written permission of Microsoft Corporation. If, however, your only

Editor: Jennifer Kerns (S&T Onsite)
Copy Editor: Shari G. Smith (R & S Consulting)
Online Program Manager: Arlo Emerson (Aditi)
Production Support: Irene Barnett (Barnett Communications)
Manufacturing Manager: Bo Galford
Manufacturing Support: Mimi Dukes (S&T Onsite)
Development Services: Kimber Dodge
Lead Product Manager: Mary Larson
Group Product Manager: Robert Stewart Module 7: Working with the Microsoft Outlook 2000 Object Model iii Instructor Notes Module 7: Working with the Microsoft
Outlook 2000 Object Model
This module provides students with a detailed understanding of the Microsoft
®

Outlook
®
2000 object model. At the end of this module, students will be able to
use Outlook development tools and the Outlook 2000 object model to develop
components of collaborative applications.
Materials and Preparation
This section provides you with the materials and preparation needed to teach
this module.
Materials
To teach this module, you need the following materials:


how to use them in an application. Explain how to handle the events of the
Application object.

Using the NameSpace Object
Describe the methods and properties of the NameSpace object and explain
how to use them in an application.

Using the MAPIFolder Object
Describe the methods and properties of the MAPIFolder object and explain
how to use them in an application.

Working with Outlook 2000 Items Programmatically
Explain how to reference items and limit the number of items returned by
using filtering. Describe how to create new items by using the CreateItem
method of the Application object and Add method of the Items collection,
and explain the difference between these two methods.

Using the Explorer Object
Explain how to use the properties, methods, and events of the Explorer
object.

Using the Inspector Object
Explain how to use the properties and methods of the Inspector object.

Working with the Outlook Bar
Provide an introduction to the Outlook Bar objects. Describe how to return
an OutlookBarPane object. Explain how to add both a new group and a
new shortcut to the Outlook Bar.

Module 7: Working with the Microsoft Outlook 2000 Object Model 1

Incorporate methods and properties of the NameSpace object in a
collaborative application.

Incorporate methods and properties of the MAPIFolder object in a
collaborative application.

Incorporate support for Explorer object methods, events, and properties in a
collaborative application.

Incorporate support for Inspector object methods, events, and properties in
a collaborative application.

Return an OutlookBarPane object and add a new group and a new shortcut
to the Outlook Bar in a collaborative application.

Slide Objective
To provide an overview of
the module topics and
objectives.
Lead-in
In this module, you will learn
how to program the
methods, events, and
properties of the Outlook
object model to add
functionality to your
collaborative applications.
2 Module 7: Working with the Microsoft Outlook 2000 Object Model
for
Applications Help.

Slide Objective
To show the Application
object in relation to other
Outlook 2000 objects.
Lead-in
Use the Application object
to access other objects in
the Outlook 2000 object
hierarchy, new
Outlook 2000 items, and
active interface objects.
Note
Module 7: Working with the Microsoft Outlook 2000 Object Model 3 Referencing the Outlook 2000 Application Object

Using the Application Object from Within a Form

Using the Application Object from Within Visual Basic

Using the Application Object from Within Visual Basic
for Applications Within Outlook 2000

Using the Application Object from Within a Folder Home
Page

Alternatively, you can set a reference to the Outlook object model and then
return a reference to the Outlook 2000 application by using the New keyword.
This approach, as demonstrated in the following example, takes advantage of
early binding.
Dim objApp As Outlook.Application
Set objApp = New Outlook.Application

Using the Application Object from Within Visual Basic for
Applications Within Outlook 2000
The Application object is provided as an intrinsic object to your Visual Basic
for Applications project when working in Outlook 2000. You can refer to the
Outlook 2000 application simply by using the word Application.
Using the Application Object from Within a Folder Home
Page
In a folder home page, you can access the Outlook 2000 application by using a
Microsoft Internet Explorer document object property, as shown in the
following example.
Dim objApp
Set objApp = Window.External.OutlookApplication

Module 7: Working with the Microsoft Outlook 2000 Object Model 5 Using Application Object Properties and Methods

Returning the Explorers and Inspectors Collections

Explorers property and Inspectors property

Application object. The following example shows how to retrieve the
Inspectors collection.
Set objInspectors = objApp.Inspectors

Slide Objective
To identify methods and
properties of the
Application object that you
can use to accomplish
common tasks.
Lead-in
Use the Explorers and
Inspectors properties to
return the Explorers and
Inspectors collections,
respectively; and use the
ActiveWindow method to
return the active window.
6 Module 7: Working with the Microsoft Outlook 2000 Object Model Returning the COMAddIns Collection
Use the read-only COMAddIns property of the Application object to return
the COMAddIns collection, which represents all the Component Object Model
(COM) add-ins currently loaded in Outlook 2000. Use the following syntax:
objApplication.COMAddIns, where objApplication is a required expression that
returns an Application object.
The following Visual Basic example displays the number of COM add-ins
currently connected.
Dim objApp As New Outlook.Application
Returning the NameSpace Object
You can use the GetNameSpace method of the Application object to return a
NameSpace object of the type you specify. Use the following syntax.
objApplication.GetNameSpace(Type)
In this syntax, objApplication is a required expression that returns an
Application object and Type is the type of NameSpace to return.

The only supported NameSpace is MAPI.

The following VBScript example uses GetNameSpace to obtain the MAPI
NameSpace object. Because this example uses VBScript, you do not create the
Application object.
Set objNS = Item.Application.GetNameSpace("MAPI")

Note
8 Module 7: Working with the Microsoft Outlook 2000 Object Model Handling Application Object Events

NewMail Event

NewExplorer and NewInspector Events

ItemSend Event

Quit Event


object events that fire within
Outlook 2000.
Lead-in
Your application can
respond to Application
object events that fire within
Outlook 2000.
Module 7: Working with the Microsoft Outlook 2000 Object Model 9 ItemSend Event
The ItemSend event fires whenever an attempt is made to send an item by using
Outlook 2000. This event returns an object, which is the item the user or
application is trying to send, and a Boolean expression named Cancel. (A
Boolean expression yields either a True or False value.) If you set Cancel to
True, Outlook 2000 stops the send action and leaves the inspector open for the
user. If you do cancel the send action, you should display an explanation in a
message box, so that users know that they need to modify the item in some way
to send the item successfully.
The following code checks to see whether a user added a subject and a category
to the message before the item is sent. The code is written in Visual Basic for
Applications within Outlook 2000.
Private Sub Application_ItemSend(ByVal Item as Object, Cancel As Boolean)
If Item.Subject = "" Then
MsgBox "You must add a subject!"
Cancel = True
ElseIf Item.Categories = "" Then
MsgBox "You must add a category!"
Cancel = True
End If

Dim WithEvents objApp As Outlook.Application

Sub Initialize_handler()
Set objApp = CreateObject("Outlook.Application")
End Sub

Private Sub objApp_Reminder(ByVal Item As Object)
Dim objReplyItem As Outlook.MailItem
If TypeName(Item) = "MailItem" Then
Set objReplyItem = Item.ReplyAll
objReplyItem.Display
End If
End Sub

Startup Event
The Startup event is fired after Outlook 2000 starts and loads any COM add-ins.
You can use this event to initialize Visual Basic for Applications programs that
you create by using Outlook 2000.
Module 7: Working with the Microsoft Outlook 2000 Object Model 11 



Using the NameSpace Object
NameSpace
Folders (MAPIFolder)
Items (Item)
Explorers (Explorer)


Folders property

Returning Available Address Lists

AddressLists propertyThree properties of the NameSpace object are particularly important to
accessing data. These properties are CurrentUser, Folders, and AddressLists.
Returning the Current User in the Outlook 2000 Session
The CurrentUser property returns the current user in the Outlook 2000 session.
Because the return value from this property is a Recipient object, you can
access more information about the user than just the user name. However, the
name of the currently logged-on user (the Name property) is probably the most-
used of the Recipient object.
Slide Objective
To identify properties of the
NameSpace object that you
can use to accomplish
common tasks.
Lead-in
You can use properties of
the NameSpace object to
return available address
lists, the current user in the
Outlook 2000 session, and a
collection of available
folders.
Delivery Tip

MAPIFolder object to perform specific actions on the folder. The following
example shows you how to display the name of all the root folders in your
folder hierarchy:
Sub cmdRootFolders_Click
Set objNS = Application.GetNameSpace("MAPI")
Set objFolders = objNS.Folders
Set objFolder = objFolders.GetFirst
Set objControls = Item.GetInspector.ModifiedFormPages("Root Folders").Controls
For i = 1 To objFolders.Count
objControls("lstRootFolders").AddItem objFolders.Item(i).Name
Next
End Sub Delivery Tip
The code for the following
procedure can be found at
\Studntcd\Demo\Module07\
RootFolders.oft.
14 Module 7: Working with the Microsoft Outlook 2000 Object Model Returning Available Address Lists
The AddressLists property returns the collection of the available address lists
for the current session. Because Outlook 2000 can support multiple types of
address lists, such as the personal address book, the Outlook 2000 address
book, and the Exchange Server Global Address List (GAL), the types of
address lists returned by this property can vary greatly.
You should check the name or type of address list being returned before
attempting to use the property. In addition, Outlook 2000 allows your users to


Accessing an Object by Using Its Unique IDThe methods of the NameSpace object provide a number of functions, such as
enabling you to do the following: create recipients; display the Outlook 2000
Select Folder dialog box; retrieve items, recipients, and folders by their unique
IDs; and allow users with proper permissions to access another user’s
information.
Retrieving Standard Outlook 2000 Folders
Outlook 2000 enables you to quickly retrieve the standard Outlook 2000
folders, such as the Inbox, Contact, and Task folders. You do not have to search
through the folder hierarchy to find them. Instead, you can pass to the
GetDefaultFolder method the Outlook 2000 constant that corresponds to the
folder you want to retrieve. VBScript in Outlook 2000 does not support
constants, so you have to use the number that corresponds to the constant, as
shown in the following example:
Sub cmdDisplayContacts_Click
Set objNS = Application.GetNameSpace("MAPI")
Set objContacts = oNS.GetDefaultFolder(10) ' Contacts
objContacts.Display
End Sub

Slide Objective
To identify some common
functions that the
NameSpace object
provides.
Lead-in
You can use methods of the

MsgBox "You did not pick a folder"
Else
objFolder.Display
End If
End Sub

Displaying the E-mail Address of a User
The CreateRecipient method takes a string as its argument. This string should
correspond to the user’s display name. If a successful object is returned to you,
you know that the recipient is in one of the address lists. At that point, you can
pass the returned Recipient object to the GetSharedDefaultFolder method in
order to open that recipient’s shared personal folders. The following code
shows you how to use the CurrentUser property to retrieve a Recipient object.
It uses the returned object to display the X.500 formatted e-mail address of the
user.
Sub cmdDisplayAddress_Click
Set objNS = Application.GetNameSpace("MAPI")
Set objRecip = objNS.CurrentUser
MsgBox objRecip.Address
End Sub For access to the proxy addresses (such as SMTP), you must use
Collaboration Data Objects (CDO) to access the Fields collection.

Delivery Tip
The code for the following
procedure can be found at
\Studntcd\Demo\Module07\
PickFolder.oft.

'
Set objTasks = objNS.GetSharedDefaultFolder(objRecip, 13)
'
' Display the contents of the folder in a new Explorer
'
objTasks.Display
End Sub

18 Module 7: Working with the Microsoft Outlook 2000 Object Model Accessing an Object by Using Its Unique ID
The EntryID property is a globally unique identifier that corresponds to the
MAPI global identifier PR_ENTRYID, which is a property of the Outlook
object. It returns the unique entry ID of the object and corresponds to the MAPI
property PR_ENTRYID. If you pass the EntryID property to any of three
methods—GetFolderFromID, GetRecipientFromID, and
GetItemFromID—the method will return the appropriate item. These methods
are helpful when you know the item’s unique ID and need to access the item
quickly, but do not have time to search through the Exchange Server
information store. For example, the following code stores the EntryID and
StoreID for the first folder in the default Tasks folder and then displays it. This
could be used within MoveApp to access the Tasks subfolders of technicians.
Sub cmdGetFolder_Click
Set objNS = Application.GetNameSpace("MAPI")

' Get the default Tasks folder
Set objTasks = objNS.GetDefaultFolder(13)

' Get the first subfolder in the collection
The MAPIFolder object represents an Outlook 2000 folder. A MAPIFolder
object can contain other MAPIFolder objects, as well as Outlook 2000 items.
The Items collection of a MAPIFolder object contains the objects that
represent all the Outlook 2000 items in the specified folder. (If a given folder
does not contain any Outlook 2000 items, the Count property for the Items
collection is 0 [zero].)
Slide Objective
To show the MAPIFolder
object in relation to other
Outlook 2000 objects.
Lead-in
You can use the
MAPIFolder object in
conjunction with the Items
collection to navigate the
Outlook 2000 folder
hierarchy.
20 Module 7: Working with the Microsoft Outlook 2000 Object Model Navigating Nested Folders

Folders Object and Parent Property Example
Function Messages_Parent()
'Assume objMessages has already been defined.
Set objMessages = objMsg.Parent
If objMessages Is Nothing Then
MsgBox "No Messages collection available."

Set objMessages = objMsg.Parent
If objMessages Is Nothing Then
MsgBox "No Messages collection available."
Exit Function
End If
MsgBox "Messages collection parent class = " & objMessages.Parent.Class
End Function

Slide Objective
To show how to
programmatically navigate
nested folders.
Lead-in
You use a combination of
the Folders object and the
Parent property to navigate
nested folders.
Module 7: Working with the Microsoft Outlook 2000 Object Model 21 Working with Folders Collection Events

Using the FolderAdd Event

Using the FolderChange Event

Using the FolderRemove EventThe Folders collection is a collection of MAPIFolder objects that represent all


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status