Consultor Eletrônico



Kbase 21793: Accessing Microsoft Outlook Application Objects in 4GL
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   2/14/2002
SUMMARY:

The Microsoft Outlook Application Object represents the entire Microsoft Outlook application. This is the highest object in the Outlook application hierarchy.

The Outlook Application Object allows access to other objects in the Outlook hierarchy and provides direct access to new items created, without having to traverse the object hierarchy tree.

The Outlook Application Object also allows access to the active interface objects involved in a given session, namely the Outlook explorer and the Outlook inspector objects.

EXPLANATION:

When you use Automation to control Microsoft Outlook from Progress 4GL, you first define a COM-HANDLE variable for the Application Object and then use the CREATE Automation Object statement to instantiate the Application Object itself, as in:

DEFINE VARIABLE hOutlook AS COM-HANDLE NO-UNDO.
CREATE "Outlook.Application" hOutlook.

The Application Object acts as the parent of all other Outlook Objects. In this Knowledge Base entry we briefly discuss the Outlook NameSpace object, the abstract root object for any data source.

The NameSpace object itself provides methods for logging in and out, accessing storage objects directly, accessing certain special default folders directly, and accessing data sources as demonstrated in the code examples below:

SOLUTION:

/* *** Code Example 1:
In this example, the NameSpace object is used to access the MAPI Folder collection object. This Folders collection represents all the available Outlook folders in a specific subset at one level of the folder tree.

Here we access the Contacts folder by setting the Outlook Folder Constant to 10. Note that each Outlook default folder has a predefined default integer constant value, as per the following table:

Folder Constant Value
olFolderCalendar 9
olFolderContacts 10
olFolderDeletedItems 3
olFolderDrafts 16
olFolderInbox 6
olFolderJournal 11
olFolderNotes 12
olFolderOutbox 4
olFolderSentMail 5
olFolderTasks 13

Hence this program fragment may be used to access any other Outlook folder by simply altering the value of the iMyOutlookFolder variable to the appropriate value.
***/

DEFINE VARIABLE iMyOutlookFolder AS INTEGER NO-UNDO INITIAL 10.

DEFINE VARIABLE hOutlook AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hMyNameSpace AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hMyFolder AS COM-HANDLE NO-UNDO.

CREATE "Outlook.Application" hOutlook.

ASSIGN
hMyNameSpace = hOutlook:GetNameSpace("MAPI")
hMyFolder = hMyNameSpace:GetDefaultFolder(iMyOutlookFolder).
hMyFolder:DISPLAY.


/* *** Code Example 2:
In this example, the NameSpace object is used to access the AddressLists collection object. The AddressLists collection object contains a set of AddressList objects. In this example we access the first Address List object, display the name of the first address entry in that list, and open the property sheet for that entry
***/

DEFINE VARIABLE hOutlook AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hMyNameSpace AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hMyFirstList AS COM-HANDLE NO-UNDO.
DEFINE VARIABLE hMyFirstEntry AS COM-HANDLE NO-UNDO.

CREATE "Outlook.Application" hOutlook.
ASSIGN
hMyNameSpace = hOutlook:GetNameSpace("MAPI")
hMyFirstList = hMyNameSpace:AddressLists(1)
hMyFirstEntry = hMyFirstList:AddressEntries:Item(1).

MESSAGE
"First Address List Name" + "~t~t" + hMyFirstList:NAME "~n"
"First Entry in the above list" + "~t~t" + hMyFirstEntry:NAME "~n"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
hMyFirstEntry:details.