Create a toolbar and add a button as shown in Listing B

Listing B.3. Adding a toolbar and button to the Inspector

Private Sub MyInspector_NewInspector(ByVal Inspector As _ Microsoft.Office.Interop.Outlook.Inspector) _ Handles MyInspector.NewInspector

If TypeOf Inspector.CurrentItem Is Outlook.ContactItem Then Try

' Assign CommandBar to variable if it exists. MyCommandBar = Inspector.CommandBars("Sample") Catch End Try

' Otherwise re-create it. If MyCommandBar Is Nothing Then

MyCommandBar = Inspector.CommandBars.Add( _ Name:="Sample", Temporary:=True)

End If Try

' Assign button to variable, if it exists. MyButton = MyCommandBar.Controls("Hello") Catch End Try

' Otherwise add the button. If MyButton Is Nothing Then

MyButton = MyCommandBar.Controls.Add( _

Type:=Microsoft.Office.Core.MsoControlType. _ msoControlButton, Temporary:=True)

End If

' Set the style and caption of the button, and then ' make it visible. With MyButton

.Style = Microsoft.Office.Core.MsoButtonStyle _

.msoButtonCaption .Caption = "Hello World" End With

MyCommandBar.Visible = True MyCommandBar.Position = _


End If End Sub

0 0

Post a comment