Hi Ken,
Thanks so much for replying to this.
The add-in does implement inspector wrappers to handle multiple inspectors.
The CommandBar UI is being added in response to the Inspectors_NewInspector
event of the Inspectors object and is removed in response to the Close event
of the Inspector object.
The code that is creating the CommandBar is as follows:
Private Sub objInspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
' Initialize an inspector wrapper and add it to the collection
Add Inspector
End Sub
Public Sub Add(AnyInspector As Outlook.Inspector)
Dim objInspWrapper As New clsInspWrapper
With objInspWrapper
Set .MyInspector = AnyInspector
.Key = nID ' "auto incrementing" collection index key
.Caption = AnyInspector.Caption
Set .Parent = Me
If AnyInspector.CurrentItem.Class = olMail Then
Set .MailItem = AnyInspector.CurrentItem
Call .AddOutlookToolbar
End If
End With
colInspWrapper.Add objInspWrapper, CStr(nID)
nID = nID + 1
End Sub
' Relevant constants
Public Const IPMessageTitle = "IPSave"
Public Const BTN_CAPTION = "IP Save"
Const IPOUT_Caption = "IP Outlook Save"
Const TLBR_OUTLOOK = "IP Save Outlook Toolbar"
Const BTN_OUTLOOK = BTN_CAPTION & " Outlook"
'following is a member of inspector wrapper class
Public Sub AddOutlookToolbar()
Dim oCommandBars As Office.CommandBars
Dim oStandardBar As Office.CommandBar
Dim oitem As Object
On Error GoTo ErrAddButton
Set oCommandBars = mobjInsp.CommandBars
If Not oCommandBars Is Nothing Then
Set oStandardBar = oCommandBars.Item(TLBR_OUTLOOK)
If oStandardBar Is Nothing Then
' Add Toolbar
Set oStandardBar = oCommandBars.Add(TLBR_OUTLOOK, , , True)
Else
'If Toolbar is Created Make sure the Button is pointing to the
correct one
If btnOutlook Is Nothing Then
Set btnOutlook = oStandardBar.Controls.Item(BTN_CAPTION)
End If
End If
If btnOutlook Is Nothing Then
For Each oitem In oStandardBar.Controls
oitem.Delete
Next
' Add Button
Set btnOutlook = oStandardBar.Controls.Add(msoControlButton, , ,
, True)
oStandardBar.Visible = False
End If
If oStandardBar.Controls.Count = 0 Then
Set btnOutlook = Nothing
Set btnOutlook = oStandardBar.Controls.Add(msoControlButton, , ,
, True)
oStandardBar.Visible = False
End If
With oStandardBar
.Position = msoBarTop
.Left = oCommandBars.Item("Standard").Left +
oCommandBars.Item("Standard").Width
.RowIndex = oCommandBars.Item("Standard").RowIndex
.Visible = True
End With
With btnOutlook
.Caption = BTN_CAPTION
.ToolTipText = BTN_OUTLOOK
.Tag = BTN_OUTLOOK & mnID
.Style = msoButtonIconAndCaption
.FaceId = 271
If Len(.OnAction) = 0 Then
.OnAction = "!<IPSaveOutlook.Connect>"
End If
.Visible = True
End With
Set oStandardBar = Nothing
End If
Set oCommandBars = Nothing
Exit Sub
ErrAddButton:
' Can't Find Save Toolbar
If Err.Number = 5 Then
Resume Next
Else
Call IPError("AddOutlookToolbar")
End If
End Sub
-----------------------------------------------------
The code that removes the CommandBar is as follows:
Private Sub mobjInsp_Close()
Call RemoveOutlookToolbar
Call Parent.Remove(mnID)
End Sub
Private Sub RemoveOutlookToolbar()
Dim oCommandBars As Office.CommandBars
Dim oStandardBar As Office.CommandBar
On Error GoTo ErrRemoveOutlookButton
Set oCommandBars = mobjInsp.CommandBars
If oCommandBars.Count > 0 Then
For Each oStandardBar In oCommandBars
If oStandardBar.Name = TLBR_OUTLOOK Then
oStandardBar.Delete
Exit For
End If
Next
End If
Set oStandardBar = Nothing
Set oCommandBars = Nothing
Exit Sub
ErrRemoveOutlookButton:
If Err.Number = 5 Then
Resume Next
Else
Exit Sub
End If
End Sub
Thanks again for taking a look at this. If the above is too much code, let
me know and I try to repost what you deem relevant.
cycloptic