Option Explicit
'Global object references
Public g_oHostApp As Object
Public g_oAddIn As Object
Public Const g_kCBItemToolbar _
As String = "Outlook Interface"
Public Const g_kCBItemTaskCaption _
As String = "Outlook Task"
Public Function ConnectCommandBar() _
As Office.CommandBarButton
'Add Toolbar for OutlookInterface
Dim oCB As CommandBar
Dim oCBC As Office.CommandBarControl
On Error Resume Next
'try connecting to existing Toolbar
Set oCB = g_oHostApp.CommandBars _
(g_kCBItemToolbar)
If oCB Is Nothing Then
'add if it doesn't exist
Set oCB g_oHostApp.CommandBars. _
Add(g_kCBItemToolbar)
End If
oCB.Visible = True
oCB.Reset
'clear out existing Toolbar
For Each oCBC In oCB.Controls
oCBC.Delete
Next
'add a button to the Toolbar
Set oCBC = oCB.Controls.Add_
(MsoControlType.msoControlButton)
oCBC.Caption = g_kCBItemTaskCaption
oCBC.Style = _
MsoButtonStyle.msoButtonCaption
'return event object & clean up
Set ConnectCommandBar = oCBC
Set oCBC = Nothing
Set oCB = Nothing
End Function
Public Sub DisconnectCommandBar()
'Remove the custom toolbar
On Error Resume Next
g_oHostApp.CommandBars (g_kCBItemToolbar).Delete
End Sub
|