Click to See Complete Forum and Search --> : CommandBar: how to...


Jean David
March 26th, 2001, 06:53 AM
Hi,

I have designed a COM addin for Outlook 2000.
I would like this addin to add a menu in the Outlook "Menu bar" at run time.
Here is my code:

Dim menuBars As Office.CommandBars
Dim menuBar As Office.CommandBar
Dim smartMenu As Office.CommandBarControl
Dim WithEvents openButton As Office.CommandBarButton


Private Sub IDTExtensibility2_OnConnection(ByVal ...

Set menuBars = hostapp.CommandBars
If menuBars Is Nothing Then
Set menuBars = hostapp.ActiveExplorer.CommandBars
End If

Set menuBar = menuBars.Item("Menu bar")

Set smartMenu = menuBar.Controls.Add(Type:=msoControlPopup)
smartMenu.Caption = "My Menu"

Set openButton = smartMenu.Controls.Add(Type:=msoControlButton)
With openButton
.Caption = "Open"
.Style = msoButtonCaption

.OnAction = "!<MyCOMAddin.Connect>"
.Visible = True
End With

...
End Sub

But it doesn't work, Outlook crashes.
What's wrong with my code?
Thanks in advance for any help.
Jean-David
jruvini@bouygues.com