The Outlook Window (Explorer Objects)
The Explorer object represents the window in which the contents of a folder are displayed. The Explorers object is the parent collection object for Explorer objects. The following sections cover some of the methods and properties for the Explorer and Explorers objects.
Figure 11-5 illustrates elements of the Outlook user interface viewed from an object model perspective. This illustration is not meant to be all-inclusive; it shows just a few of the objects in the Outlook Object Model that you can manipulate programmatically.
Figure 11.5 - Object model components of the Outlook user interface.
For a complete list and description of the properties, methods, and events for the Explorer and Explorers objects, see Microsoft Outlook Visual Basic Reference Help.
Open the Explorer object item in the VBScript Samples folder to work directly with this code in Outlook.
Explorer Methods
Creating a New Explorer Window
Outlook supports an Explorers collection object. You can use the Explorers object to add a new Explorer window for a specific folder. Use the Display method to present the new Explorer window. The following example creates a new Explorer window for the Drafts folder by using the Add method and then shows the new window on the desktop in a normal window state.
Const olNormalWindow = 2 Sub DisplayNewExplorer_Click Set myExplorers = Application.Explorers Set myFolder = Application.GetNameSpace("MAPI").GetDefaultFolder(16) Set myOlExpl = myExplorers.Add(myFolder, 2) myOlExpl.Display
myOlExpl.WindowState = olNormalWindow End Sub
Explorer Properties
Returning the Active Folder
You can use the CurrentFolder property of the Explorer object to return the active folder in the Outlook window. The following example shows the name of the active folder in the message box when the DisplayTheCurrentFolder control is clicked:
Sub DisplayTheCurrentFolder_Click Set myExplorer = Application.ActiveExplorer MsgBox "The current folder in the Explorer is: " _ & myExplorer.CurrentFolder.Name, vbInformation End Sub
Obtaining the Current View for the Active Explorer
You can use the CurrentView property of the Explorer object to return or set the current view for the Active Explorer window. The example displays the name of the current view for the Active Explorer window.
Sub DisplayTheExplorerView_Click Set myExplorer = Application.ActiveExplorer MsgBox "The current Explorer view is: " & vbCr _ & myExplorer.CurrentView, vbInformation End Sub
Determining Which Items are Selected in the Explorer
The Selection collection object lets you know which items are selected in the Explorer window. The Selection object, in turn, contains an Items collection that lets you iterate over selected items. If you are writing VBA code, you can respond to the SelectionChange event of the Explorer object. The following example displays the number of selected items in the Active Explorer and then asks whether the user wants to display the items:
Sub DisplaySelectedItems_Click DisplayNewExplorer_Click Set mySelection = Application.ActiveExplorer.Selection MsgBox "The number of selected items in the Explorer is " _ & mySelection.Count, vbInformation If MsgBox ("Display selected items?", vbYesNo+vbQuestion) = vbNo Then Exit Sub End If For i = 1 to mySelection.Count Set myItem = mySelection.Item(i) myItem.Display Next End Sub
No comments:
Post a Comment