Finally replace the code you previously added to the This Application class with the code in Listing B

Listing B.7. Creating a new CommandBar

Dim WithEvents MyInspectors As Outlook.Inspectors

Private Sub ThisApplication_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup

MyInspectors = Me.Inspectors

End Sub

Private Sub ThisApplication_Shutdown(ByVal sender _ As Object, ByVal e As System.EventArgs) _ Handles Me.Shutdown

End Sub

Private Sub MyInspectors_NewInspector(ByVal Inspector As _ Microsoft.Office.Interop.Outlook.Inspector) _ Handles MyInspectors.NewInspector

If TypeOf Inspector.CurrentItem Is _ Outlook.ContactItem Then

Dim CommandBar As New ContactCommandBar(Inspector) End If

End Sub

Now when you press F5 to run the code and then open a contact item, the button is created; a button also is created for any contact item that you create or open.

To handle other types of Inspectors, you could create additional classes similar to the ContactCommandBar class that derive from Command-BarBase, or you could create a generic class that handles all Inspectors. Note, however, that this code is not enabled for e-mail items when Word is selected as the editor for e-mail. You can change these settings by deselecting the Use Microsoft Office Word 2003 to Edit E-mail Messages check box and the Use Microsoft Office Word 2003 to Read Rich Text E-mail Messages check box, as shown in Figure B.2. Adding support for Word as the editor is beyond the scope of this example, but you could extend the basic framework of the example to support WordMail.

Figure B.2. Clearing the Use Microsoft Office Word 2003 check boxes

0 0

Post a comment