Listing 11.1 showed how to use Visual Basic's For Each loop to iterate over the Explorers and the Inspectors collections. It is also possible to get to an Explorer or Inspector using the index operator () and passing an index as an Object. That index can be a 1-based index into the array of Explorers or Inspectors, or it can be a String index that is the caption of the Explorer or inspector window in the array. Listing 11.4 illustrates using both types of indices with the Explorers and Inspectors collections. Listing 11.4 also illustrates how to create a new Inspector and Explorer window. Both the Explorers and Inspectors collections have an Add method. The Explorers collection's Add method takes a Folder parameter of type MAPIFolder, which is the folder for which to display a new Explorer window. It takes a second optional parameter of type OlFolderDisplayMode that enables you to set the initial display used in the newly created Explorer window. The Add method returns the newly created Explorer object. To show the newly created Explorer object, you must then call the Explorer object's Display method. The Inspectors collection's Add method takes an Object parameter, which is the Outlook item for which to display an inspector window. In Listing 11.4, we get an Outlook item out of the Inbox folder and create an inspector window for it. To show the newly created Inspector object, you must then call the Inspector object's Display method, which takes an optional parameter called Modal of type Object to which you can pass true to show the Inspector as a modal dialog box or False to show the Inspector as a modeless dialog box. If you omit the parameter, the parameter defaults to False. Listing 11.4. A VSTO Add-In That Works with Explorer and Inspector Windows
|