Methods, Properties, and Events


Methods , Properties, and Events

Next we'll look at methods and properties of other Outlook objects as well as a host of events that your applications can use to receive notifications from Outlook.

Application Object

Recall that the Application object is the topmost object in the Outlook object model. You must create an Application object before you create any other objects. Let's take a look at some of the methods, properties, and events of the Application object.

ActiveWindow Method

The ActiveWindow method returns the object that represents the topmost Outlook window on the desktop. The return type for this object can be an Explorer object or an Inspector object. If no Explorer or Inspector object is open , this method returns Nothing . You use this method to determine which object the current user is viewing and, if necessary, to change the state of that object. The following code shows how to use the ActiveWindow method:

 Set oWindow = oApp.ActiveWindow If Not (oWindow Is Nothing) Then     If oWindow.Class = olExplorer Then         strTop = "Explorer"     ElseIf oWindow.Class = olInspector Then         strTop = "Inspector"     End If     MsgBox "The topmost object is a(n) " & strTop & " object." End If 

AnswerWizard Property

The AnswerWizard property returns an AnswerWizard object for the application. For more information about the AnswerWizard object model, see the Office documentation.

COMAddIns Property

The COMAddIns property returns a COMAddIns collection that represents all COM add-ins currently loaded and connected in Outlook. You can use this collection to quickly access COM add-ins and their exposed objects. The following example shows how to use the COMAddIns property:

 Dim oCOMAddins As Office.COMAddIns Dim oCOMAddin As Office.COMAddIn      Set oCOMAddins = oApp.COMAddIns strName = vbLf For Each oCOMAddin In oCOMAddins     strName = strName & vbLf & oCOMAddin.ProgId Next MsgBox "The COM Add-Ins ProgIDs in Outlook are: " & _        strNameExplorers 

CopyFile Method

The CopyFile method copies a file from the file system to a folder you specify in Outlook. The first parameter you must specify is the path to the file you want to copy. The second parameter is the Outlook path to the folder you want to copy the item to. The path defaults to the mailbox of the user, so entering Inbox\Test for this parameter copies the item to the Test folder under the Inbox. To copy the item to a public folder, use \\Public Folders\All Public Folders\<Folder> .

Explorers and Inspectors Properties

The Explorers property returns the Explorers collection. The Inspectors property returns the Inspectors collection. We covered these collections earlier in this chapter.

LanguageSettings Property

The LanguageSettings property returns a LanguageSettings object that you can use to retrieve language- related information about Outlook. For example, you can retrieve the install language, the user interface language, and the help language for Outlook. You can use this information in COM add-ins to load the proper resource string for a user interface, based on the information you obtain from the LanguageSettings object.

ProductCode Property

The ProductCode property returns a string that is the globally unique identifier (GUID) for the Outlook product. If you need to identify Outlook in your COM add-ins or applications, you can use this GUID to identify it.

ItemSend Event

The ItemSend event fires when a user or an application uses Outlook to attempt to send an item. This event returns an object for the item and a Boolean named Cancel . If you set Cancel to True , Outlook will stop the send action and leave the Inspector open for the user. If you do cancel the send, you should display an explanation in a message box so users will know what they need to add or delete to successfully send the item. The following code checks to see whether a user added a subject and a category to his message. Note that the ItemSend event does not fire when a user posts an item to a folder. In this case, you should monitor the folder for the ItemAdd event.

 Dim WithEvents oApp As Outlook.Application      Private Sub oApp_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 have a category!"         Cancel = True     End If End Sub 

MAPILogonComplete Event

The MAPILogonComplete event fires after the OnStartupComplete event and guarantees that you have a valid MAPI session with the server so that all properties and methods are available across the Outlook object model.

NewMail Event

The NewMail event fires when a new item is received in the Inbox of the current user. This event does not pass any parameters, nor is there any one-to-one correspondence between the number of arriving messages and the number of times this event fires; even if the Inbox receives many new messages, Outlook might fire this event only once. The following code shows how to use the NewMail event:

 Private Sub oApp_NewMail()     MsgBox "You have received new mail!" End Sub 

OptionsPagesAdd Event

For information about the OptionsPagesAdd event, see the Account Tracking application in Chapter 8.

Quit Event

The Quit event is fired when Outlook begins to close. Using this event, you can persist any settings or other information as well as destroy any objects that are left open by your application.

Reminder Event

The Reminder event is fired immediately before a reminder is displayed. This event passes one parameter, which is an object that corresponds to the item firing the reminder. There is no Cancel parameter for this event, so you cannot keep the reminder from appearing, but this event allows you to take other actions based on the reminder. The following example shows how to use the Reminder event:

 Private Sub oApp_Reminder(ByVal Item As Object)     MsgBox "The following item " & Item.Subject & " has " & _            "fired a reminder." End Sub 

Startup Event

The Startup event is fired after Outlook and any of its COM add-ins have been loaded. You can use this event to initialize VBA programs that you created with Outlook.

NameSpace Object

The NameSpace object has been enhanced incrementally through successive versions of Outlook. The features you are mostly likely to use in your applications are the ability to dynamically add a .pst file to the NameSpace object and the ability to create custom property pages for folders. Let's examine more closely these aspects of the NameSpace object.

SyncObjects Property

The SyncObjects property returns the SyncObjects collection for the NameSpace object. We covered the SyncObjects collection earlier in the chapter.

AddStore Method

The AddStore method allows you to dynamically connect an existing .pst file to Outlook and to create a new .pst file. This method takes one parameter, which is a path to the .pst file you want to access or create. If you pass in a path for the .pst file and the .pst file doesn't exist, Outlook will create the file. You can then retrieve the information in the .pst file by using the Outlook object model. The following example shows how to use the AddStore method to access an existing .pst file:

 oNS.AddStore "c:\my new store.pst"      'Retrieve a folder from the newly connected store Set oFolder = oNS.Folders("Personal Folders").Folders("My Folder")      'Display the folder oFolder.Display 

Dial Method

The Dial method is a new method. Outlook allows you to dial a contact's phone number directly, just as you can do from the contact item itself. You can optionally pass a Contact object as a parameter, which populates the Dial dialog box with the contact's information. If you do not specify a contact, a blank dial screen will be displayed.

Offline Property

The Offline property is a Boolean property that returns whether the user is working on line or off line. You no longer have to use CDO to determine this status.

OptionsPagesAdd Event

For more information about this event, see the Account Tracking application in Chapter 8.

RemoveStore Method

The RemoveStore method removes the store that you pass as a MAPIFolder object from Outlook. It does not delete the store, and you cannot remove the standard mailbox store. This operation is the same as right-clicking on the root folder of a store and choosing Close StoreName.

Explorer Object

Outlook developers have often requested more granular control over how Explorer s and Inspector s are displayed on the screen. With Outlook 2003, you can control the location of your Explorer and Inspector windows and also receive events from these objects that indicate what the user is doing in the user interface. In addition, the Explorer object adds a number of new events. Let's take a look at the recent additions to the Explorer object.

Caption Property

The Caption property returns the string for the Explorer window text. This property is read-only.

CurrentView Property

The CurrentView property returns or sets the view for the Explorer . When you set this property, you cause the BeforeViewSwitch and ViewSwitch events to fire on the Explorer object. Because Outlook supports only a single initial view of a folder, you can use this property to customize per-user settings for the initial view. To do this, you use the FolderSwitch event for the Explorer object. When this event fires, you check the current folder and current user and then set the CurrentView property appropriately. The following code snippet shows an example of this functionality:

 Dim WithEvents oExplorer As Outlook.Explorer Private Sub oExplorer_FolderSwitch() On Error Resume Next     If oExplorer.CurrentFolder.Class = olFolder Then         If oExplorer.CurrentFolder.Name = "Contacts" Then             If oNS.CurrentUser.Name = "Thomas Rizzo" Then                 oExplorer.CurrentView = "By Category"             End If         End If     End If End Sub 

Height Property

The Height property returns or sets the height of the Explorer window in pixels. You can use this property to change the height of your Explorer window.

HTMLDocument Property

The HTMLDocument property returns the HTML document for the home page for the current folder in the Explorer object. You can then script the HTML document object model to implement your functionality.

Left Property

The Left property returns or sets the distance, in pixels, from the left edge of the screen to the left edge of the Explorer window.

Panes Property

The Panes property returns the Panes collection for the Explorer object. We covered the Panes collection earlier in the chapter.

Selection Property

The Selection property returns a Selection collection, which enables you to access the items currently selected by the user. We covered the Selection collection earlier in the chapter.

Top Property

The Top property returns or sets the distance, in pixels, from the top edge of the screen to the top edge of the Explorer window.

Width Property

The Width property returns or sets the width of the Explorer window in pixels.

WindowState Property

The WindowState property returns or sets the window state. The possible values for this property include olMaximized (1) , olMinimized (2) , and olNormalWindow (3) . The next code sample uses the Top , Width , Left , and Height properties to move an Explorer window around the screen. Notice that the code first sets the WindowState property to olNormalWindow . Outlook will return an error if the window is already maximized or minimized when you try to set these properties.

 oExplorer.WindowState = olNormalWindow oExplorer.Top = 100 oExplorer.Width = 200 oExplorer.Left = 300 oExplorer.Height = 100 

Activate Method

The Activate method activates an Explorer object by bringing it to the foreground and giving it keyboard focus. You can use this method to highlight a specific Explorer or Inspector window for your application.

IsPaneVisible Method

The IsPaneVisible method returns a Boolean that specifies whether a particular pane is visible in the Explorer window. You pass the desired pane as a parameter to this method. The possible values you can pass are olOutlookBar (1) , olFolderList (2) , and olPreview (3) . You use the IsPaneVisible method in conjunction with the ShowPane method, which is described next.

ShowPane Method

The ShowPane method hides or displays a specific pane in your Explorer window. You must pass to this method the pane you are interested in as well as a Boolean parameter that is set to True to display the pane or False to hide the pane. The following code shows how to use the IsPaneVisible method with the ShowPane method to hide and display panes in an Explorer window:

 'Flip the settings that the user already has boolFolderList = oExplorer.IsPaneVisible(olFolderList) boolOutlookBar = oExplorer.IsPaneVisible(olOutlookBar) boolPreviewPane = oExplorer.IsPaneVisible(olPreview)      oExplorer.ShowPane olFolderList, Not (boolFolderList) oExplorer.ShowPane olOutlookBar, Not (boolOutlookBar) oExplorer.ShowPane olPreview, Not (boolPreviewPane) 

Activate Event

The Activate event is fired when an Explorer window or an Inspector window becomes the active window. You can use this event to determine whether a specific Explorer or Inspector window becomes the active window and then customize the toolbar for that window. The following code shows how to use this event:

 Dim WithEvents oExplorer as Outlook.Explorer      Private Sub oExplorer_Activate()    MsgBox "This Explorer window has become active!" End Sub 

BeforeFolderSwitch Event

The BeforeFolderSwitch event occurs before the Explorer navigates to the new folder. This event passes an object that represents the folder the user is trying to navigate to and also a Boolean parameter named Cancel . To keep the current folder active and prevent the user from navigating to the new folder, set Cancel to True . If the user navigates to a folder in the file system, the BeforeFolderSwitch event will not pass an object for that folder. For an example of this event in action, see the Account Tracking application in Chapter 8.

BeforeItemCopy Event

The BeforeItemCopy event fires before an item is copied to the Clipboard. This event is cancelable.

BeforeItemCut Event

The BeforeItemCut event fires before an item is cut and moved to the Clipboard. This event is cancelable.

BeforeItemPaste Event

The BeforeItemPaste event fires before a user pastes an item from the Clipboard or when a user drags and drops an item from one folder to another. This event is cancelable and passes the Clipboard contents and the target folder for the paste operation.

BeforeMaximize Event

The BeforeMaximize event fires before the Explorer window is maximized. This event is cancelable.

BeforeMinimize Event

The BeforeMinimize event fires before the Explorer window is minimized. This event is cancelable.

BeforeMove Event

The BeforeMove event fires before the Explorer window is moved to a different location. This event is cancelable.

BeforeSize Event

The BeforeSize event fires before a window is resized but not before a window is restored. This event is cancelable.

BeforeViewSwitch Event

The BeforeViewSwitch event fires when a user tries to switch views. This event passes the name of the view the user is trying to switch to as well as the Boolean variable Cancel . To cancel the change in views and maintain the user's current view, set Cancel to True . The following code shows how to use the BeforeViewSwitch event:

 Private Sub oExplorer_BeforeViewSwitch(ByVal NewView As Variant, _                                        Cancel As Boolean)     If NewView = "By Category" Then         Cancel = True     End If End Sub 

Close Event

The Close event fires when the Explorer window is being closed. You will generally listen for this event only when you're developing COM add-ins that need to correctly destroy Explorer objects or the variables that reference them.

Deactivate Event

The Deactivate event fires when the Explorer or Inspector window is no longer the active window. This event does not pass any parameters.

FolderSwitch Event

The FolderSwitch event fires after a user successfully switches folders. This event does not pass any parameters.

SelectionChange Event

The SelectionChange event fires after the user selects a different item in the current view. This event does not pass any parameters. The following code shows how to use this event with the Selection collection:

 Private Sub oExplorer_SelectionChange()     On Error Resume Next     Set oSelection = oExplorer.Selection     strName = vbLf     For Each oItem In oSelection         strName = strName & vbLf & oItem.Subject     Next     MsgBox "New Selection: " & strName End Sub 

ViewSwitch Event

The ViewSwitch event fires when the user successfully changes the view in the Explorer window. This event does not pass any parameters.

Sample Code for Events

The following code shows you how to use a number of the events just described:

    Dim WithEvents oExplorer As Outlook.Explorer Dim oApp As New Outlook.Application Set oExplorer = oApp.ActiveExplorer    Private Sub oExplorer_BeforeItemCopy(Cancel As Boolean)     If oExplorer.Selection.Count = 1 Then         MsgBox "You are copying 1 item called " & _                oExplorer.Selection.Item(1).Subject     Else         MsgBox "You are copying " & oExplorer.Selection.Count & " items."         Dim oSelection As Outlook.Selection         For x = 1 To oExplorer.Selection.Count             MsgBox "Item Name: " & oExplorer.Selection.Item(x).Subject         Next     End If End Sub      Private Sub oExplorer_BeforeItemCut(Cancel As Boolean)     If oExplorer.Selection.Count = 1 Then         MsgBox "You are copying 1 item called " & _                oExplorer.Selection.Item(1).Subject     Else         MsgBox "You are copying " & oExplorer.Selection.Count & " items."         Dim oSelection As Outlook.Selection         For x = 1 To oExplorer.Selection.Count             MsgBox "Item Name: " & oExplorer.Selection.Item(x).Subject         Next     End If End Sub      Private Sub oExplorer_BeforeItemPaste(ClipboardContent As Variant, _             ByVal Target As Outlook.MAPIFolder, Cancel As Boolean)     'See what they are trying to paste     If TypeOf ClipboardContent Is Selection Then         'Scroll through the selection to make sure we will allow the paste         For x = 1 To ClipboardContent.Count             'check some variable             If ClipboardContent.Item(x).Subject = "No Paste" Then                 Cancel = True             End If         Next     End If End Sub      Private Sub oExplorer_BeforeMaximize(Cancel As Boolean)     MsgBox "Maximizing!" End Sub      Private Sub oExplorer_BeforeMinimize(Cancel As Boolean)     MsgBox "Minimizing!" End Sub      Private Sub oExplorer_BeforeMove(Cancel As Boolean)     MsgBox "Moving!" End Sub      Private Sub oExplorer_BeforeSize(Cancel As Boolean)     MsgBox "Sizing!" End Sub 

Inspector Object

The properties, methods, and events of the Inspector object are the same as their Explorer object counterparts that I've described, so I'll simply list them. For details, you can refer back to the descriptions provided earlier.

  • Caption property

  • Height property

  • Top property

  • Width property

  • WindowState property

  • Activate method

  • Activate event

  • BeforeMaximize event

  • BeforeMinimize event

  • BeforeMove event

  • BeforeSize

  • event

  • Deactivate event

  • Close event

Folders Collection

The Folders collection contains three new events: FolderAdd , FolderChange , and FolderRemove .

FolderAdd Event

The FolderAdd event fires when a folder is added to the Folders collection. This event passes the added folder as a MAPIFolder object. You cannot cancel this event. You might want to hook into this event to prompt the user to add a folder to a specific group on the Outlook Bar. The following code shows how to use the FolderAdd event:

    Dim WithEvents oFolders As Outlook.Folders Set oFolders = oNS.Folders("Mailbox - Thomas Rizzo").Folders    Private Sub oFolders_FolderAdd(ByVal Folder As Outlook.MAPIFolder)     MsgBox "You have added the " & Folder.Name & " folder!" End Sub 

FolderChange Event

The FolderChange event fires when some property of the specified Folders collection ”such as all the items in the folder ”are deleted. This event passes the changed folder as a MAPIFolder object, but it does not pass the actual folder property that was changed. You must figure out programmatically which property was changed. You can't cancel this event. The following code shows how to use the FolderChange event:

 Private Sub oFolders_FolderChange(ByVal Folder As Outlook.MAPIFolder)     MsgBox "You changed the " & Folder.Name & " folder!" End Sub 

FolderRemove Event

The FolderRemove event fires when a folder is removed from the collection. It does not pass any parameters, so if you need to know which folder was removed, your code has to figure that out. Outlook notifies you only that some folder was removed. You can't cancel the FolderRemove event.

MAPIFolder Object

The MAPIFolder object provides three interesting properties that are described in Chapter 8: WebViewAllowNavigation , WebViewOn , and WebViewURL . The other properties, methods, and events of the MAPIFolder object are described next.

AddressBookName Property

The AddressBookName property is a string property that can get or set the name to use when you display the Contact address book in the address book selection interface.

AddToFavorites Method

The AddToFavorites method adds the current folder to the favorites list in Microsoft Internet Explorer. It takes two optional parameters. The first is a Boolean that specifies whether to display the standard user interface for naming the folder and selecting the location. If you specify True for this parameter, the second parameter will be the name of the folder.

AddToPFFavorites Method

The AddToPFFavorites method adds the current folder to the Public Folder Favorites folder. You can add only public folders to the Public Folder Favorites folder.

CustomViewsOnly Property

The CustomViewsOnly property is a Boolean property that you can use to specify whether to display only custom views for the folder.

FolderPath Property

The FolderPath property returns a string indicating the path to the current folder, such as \\Public Folders\All Public Folders\My Folder .

InAppFolderFolderSyncObject Property

The InAppFolderFolderSyncObject property is a Boolean property that gets or sets whether the current folder is in the Application Folders Send/Receive group. You can then programmatically synchronize the Application Folders group that contains the folder.

ShowAsOutlookAB Property

The ShowAsOutlookAB property is a Boolean property that specifies whether to show the current folder as an Outlook address book so users can browse and resolve names against the folder. This method works only with contact folders.

Views Collection

Returns the Views collection for the folder. We covered the Views collection earlier in the chapter.

Items Collection

Recall that the Outlook Items collection is a collection of objects in a particular folder. The type of object the Items collection contains depends on the items in the folder. For example, in your Calendar folder, the Items collection will most likely contain AppointmentItem objects. We'll look at the enhancements to the Items collection next.

ItemAdd Event

The ItemAdd event fires when a new item is added to the folder. This event returns an object for the item added to the folder's collection. Remember that before you attempt to call methods or properties on a returned object, you should check which type of object was returned. It might not be the type you expected and might cause unwanted behavior in your application. For an example of how to use this event, see the Account Tracking application in Chapter 8.

ItemChange Event

The ItemChange event fires when an item in the collection is changed in any way. The event passes an object for the item that was changed; it does not pass the changed property. This means you must use your code to determine what was changed on the item. For an example of using this event, see the Account Tracking application in Chapter 8.

ItemRemove Event

The ItemRemove event fires when an item is removed or deleted from the collection. This event does not pass any parameters, so your code must figure out which items were deleted from the collection.

Characteristics of Item Types

We'll look next at some characteristics of all the item types in Outlook, such as the PostItem , the MailItem , and the AppointmentItem objects. The events I'll discuss can be used with Visual Basic, VBA, and VBScript. The examples are written using VBScript.

Links Property

The Links property returns the Links collection for the object. We covered the Links collection earlier in the chapter.

AttachmentAdd Event

The AttachmentAdd event fires after an attachment has been added to an Outlook item. This event passes the attachment as an Attachment object. Once the object is passed, you can perform tasks such as checking the attachment for viruses before the user sends the item. You cannot, however, cancel or stop the user from adding an attachment to the item. The following VBScript example shows how to use this event:

 Sub Item_AttachmentAdd(ByVal NewAttachment)     If NewAttachment.Type = 1 Then         Item.Save         If Item.Size > 10000 then             MsgBox "Sending a message with an attachment this large" & _                    " may take a long time."         End If     End If End Sub 

AttachmentRead Event

The AttachmentRead event fires after an attachment has been opened for reading; it passes the attachment as an Attachment object. You can use this event to perform certain actions when the user opens the attachment, such as making a backup copy of the attachment or marking this attachment as checked out for a document management solution. The following example shows how to prompt the user to save changes when the user opens an attachment to read it:

 Sub Item_AttachmentRead(ByVal ReadAttachment)     If ReadAttachment.Type = 1 Then         MsgBox "Make sure to save any changes that " & _                "you make to the attachment."     End If End Sub 

BeforeAttachmentSave Event

The BeforeAttachmentSave event fires before an attachment is saved with the item. This event is supported in VBScript, Visual Basic, and VBA, so you must follow the appropriate syntax. When you use this event in VBScript that's automating an Outlook form, the BeforeAttachmentSave event passes the attachment that is trying to be saved as an Attachment object. If you're using Visual Basic or VBA, this event passes both the attachment and a Boolean parameter named Cancel . To abort the save, set Cancel to True . The next two code examples show a VBScript version and a Visual Basic/VBA version of this event, respectively. Notice that the VBScript version is a function and the Visual Basic/VBA version is a subroutine.

 Function Item_BeforeAttachmentSave(ByVal SaveAttachment)     If SaveAttachment.Type = 1 then         If SaveAttachment.FileName = "sales.mdb" Then             MsgBox "You cannot save this file!"             Item_BeforeAttachmentSave = False         End If     End if End Function      Private Sub oMailItem_BeforeAttachmentSave( _             ByVal Attachment As Outlook.Attachment, Cancel As Boolean)     If Attachment.Type = 1 then         If Attachment.FileName = "sales.mdb" Then             MsgBox "You cannot save this file!"             Cancel = True         End If     End if End Sub 

BeforeCheckNames Event

The BeforeCheckNames event fires before Outlook starts resolving names for the recipients of an item. You can use this event to check the names of the recipients from a data source such as a database. This event, like the BeforeAttachmentSave event, uses different syntax depending on whether you call the event from VBScript or Visual Basic/VBA. In VBScript, this event is implemented as a function that you can cancel by setting the name of the function to False . In Visual Basic/VBA, you are passed a Boolean parameter named Cancel . To cancel the name resolution, you set Cancel to True . Here are examples that show the VBScript version and the Visual Basic/VBA version:

 Function Item_BeforeCheckNames()     'You can use this event to cancel Outlook's resolution     'And put your own resolution in     Item_BeforeCheckNames = False End Function      Private Sub oMailItem_BeforeCheckNames(Cancel As Boolean)     'You can use this event to cancel Outlook's resolution     'And put your own resolution in     Cancel = True End Sub 

SyncObjects Collection

The SyncObjects collection has been enhanced to support Application Folders. These are folders that a user or developer can add to a particular synchronization group called AppFolders. When synchronization occurs, the application folder is synchronized off line.

AppFolders Property

The AppFolders property returns the Application Folders' SyncObject. This SyncObject contains all Application Folders that you add programmatically to the application folders group using the InAppFolderSyncObject property.

ContactItem Enhancements

Two enhancements have been added to ContactItem , the IMAddress property and the LastFirstNoSpaceandSuffix property.

IMAddress Property

The ContactItem property gets or sets the Instant Messaging (IM) address for the contact.

LastFirstNoSpaceandSuffix Property

The LastFirstNoSpaceandSuffix property is used only when the first name, last name, or suffix field contains Asian (double-byte) characters .

Other Methods

Table 6-8 lists methods not covered elsewhere in this chapter. These methods work only in Outlook 2002.

Table 6-8: Additional Important Methods of Outlook Objects

Method

Object

Description

SaveAs

Multiple item types

This method is not new, but there are new SaveAs types. You can now save contacts as vCards by passing in olVCard , or you can save appointments as iCal appointments by passing in olICal .

ShowCategoriesDialog

Any Outlook item object

Displays the Categories dialog box for the item.

Other Properties

Table 6-9 describes properties that have not been covered elsewhere in the chapter.

Table 6-9: Additional Important Properties of Outlook Objects

Property

Object

Description

BodyFormat

MailItem , PostItem

Returns or sets the format for the body of a message. The constants you can use with this property are:

  • olFormatHTML

  • olFormatPlain

  • olFormatRichText

  • olFormatUnspecified

DownloadState

All Outlook items

Returns or sets the download state for an item. You can use the following constants:

  • olFullItem

  • olHeaderOnly

InternetCodepage

AppointmentItem , MailItem , PostItem , TaskItem

Returns a Long value that is the Internet code page used by the item. For example, US English is hex value 4E9F .

IsConflict

All Outlook items

A Boolean property that indicates whether the current item is in conflict. You can then access the attachments collection to get the different versions of the conflicted message.

MarkForDownload

All Outlook items

Determines the status of an item after you have received the item. You can use the following constants with this property:

  • olMarkedForCopy

  • olMarkedForDelete

  • olMarkedForDownload

  • olRemoteStatusNone

  • olUnMarked

Other Events

Table 6-10 describes events added to Outlook 2002 that have not been described elsewhere in the chapter.

Table 6-10: Additional Important Events for Outlook Objects

Event

Object

Description

BeforeDelete

All Outlook items

Fires before an item is deleted in Outlook. The item must be open in an Inspector window for this event to fire. If the user simply deletes the item from a view, this event does not fire. Synchronous events in Exchange 2000 are better for capturing delete events.

start sidebar
Setting Calendar Color with the Appointment Property

The Outlook Object Model does not have a way to query or set calendar color coding. However, you can use Collaboration Data Objects (CDO) to query and set the calendar color coding. You use the Appointment property set ( 0220060000000000C000000000000046 ); the property for the color is 0x8214 . The following quick sample shows you how to query this property using both CDO 1.21 and CDO for Exchange:

 Dim oSession As New MAPI.Session 'CDO 1.21 Version oSession.Logon Dim oFolder As MAPI.Folder Set oFolder = oSession.GetDefaultFolder(0) Dim oItem As MAPI.AppointmentItem Dim oMessages As MAPI.Messages      Set oItem = oFolder.Messages.GetFirst MsgBox oItem.Fields.Item("0x8214", "0220060000000000C000000000000046") 'Values here will mimic the Outlook user interface '0 = No color '1 = 1st label (Important) '2 = 2nd label (Business) '3 = 3rd label (Personal) 'etc oSession.Logoff      'CDO for Exchange version Dim oAppt As New CDO.Appointment strURL = "file://./backofficestorage/thomriznt5dom2.extest." & _          "microsoft.com/mbx/thomriz/calendar/appt.eml"      oAppt.DataSource.Open strURL 'Propset is 00062002-0000-0000-C000-000000000046 'For CDO 1.21, this is transposed to 0220060000000000C000000000000046 'Property ID is 0x8214 MsgBox oAppt.Fields.Item("http://schemas.microsoft.com/mapi/id/" & _     "{00062002-0000-0000-C000-000000000046}/0x00008214").Value 
end sidebar
 



Programming Microsoft Outlook and Microsoft Exchange 2003
Programming MicrosoftВ® OutlookВ® and Microsoft Exchange 2003, Third Edition (Pro-Developer)
ISBN: 0735614644
EAN: 2147483647
Year: 2003
Pages: 227
Authors: Thomas Rizzo

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net