The inspector for the selected customer was not active. after declaring
myItem as Contactitem with events and moving the command bar handling to
myItem_read
everything seems to work.
and if anybody is interessted, here is the working code which has to be
place in ThisOutlookSession.
Regards
Willem
Option Explicit
Public myOlApp As New Outlook.Application
Public WithEvents myOlInspectors As Outlook.Inspectors
Public WithEvents myItem As Outlook.ContactItem
Private Sub Application_Startup()
Set myOlInspectors = myOlApp.Inspectors
End Sub
Public Sub myOlInspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
If Inspector.CurrentItem.Class = olContact Then
Set myItem = Inspector.CurrentItem
End If
End Sub
Private Sub myItem_Read()
addMyMenu
End Sub
Public Sub addMyMenu()
Dim colCB As Office.CommandBars
Dim objCB As Office.CommandBar
Dim objCBMenu As Office.CommandBarPopup
Dim objCBMenuCB As Office.CommandBar
Dim objCBB As Office.CommandBarButton
Set colCB = myOlApp.ActiveInspector.CommandBars
Set objCB = colCB.Item("Menu Bar")
Set objCBMenu = objCB.Controls.Add(Type:=msoControlPopup,
Temporary:=True)
With objCBMenu
.Caption = "Spezial"
Set objCBMenuCB = .CommandBar
Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, ID:=1,
Temporary:=True)
objCBB.Caption = "Besuchsbericht"
objCBB.OnAction = "erfassKontakt2"
Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, ID:=1,
Temporary:=True)
objCBB.Caption = "Kontakt kopieren"
objCBB.OnAction = "copy_contact_info"
Set objCBB = objCBMenuCB.Controls.Add(Type:=msoControlButton, ID:=1,
Temporary:=True)
objCBB.Caption = "Angebot"
objCBB.OnAction = "Angebotsanfrage"
End With
Set myOlApp = Nothing
Set colCB = Nothing
Set objCB = Nothing
Set objCBMenu = Nothing
Set objCBMenuCB = Nothing
Set objCBB = Nothing
End Sub