Office code works in Access, not in Outlook : re CommandBar

C

Composer

I want to add an item to the Menu Bar in Outlook 2000.

The code below works fine in Access 2000.

In Outlook, it runs and causes no errors, but the result is not visible
in the menu bar.

Can someone help me understand why it acts differently in the two
applications?

Thanks.

-------------------------------------------------------------------

Public Sub MenuTest()

Dim cbr As CommandBar
Dim cbc As CommandBarControl
Dim ctlHelp As CommandBarControl
Dim ctlMyself As CommandBarPopup
Dim ctlHello As CommandBarButton

Set cbr = CommandBars("Menu Bar")

' Delete my previous effort, if found.
Set cbc = cbr.FindControl(Tag:="me", recursive:=False)
If Not (cbc Is Nothing) Then cbc.Delete

' Insert my item into the main Menu Bar.
Set ctlHelp = cbr.Controls("Help")
Set ctlMyself = cbr.Controls.Add(msoControlPopup,
Before:=ctlHelp.Index, Temporary:=True)
With ctlMyself
.Caption = "Myself"
.Tag = "me"
.Visible = True
End With

' Insert one action item below my menu item.
Set ctlHello = ctlMyself.Controls.Add(msoControlButton,
Temporary:=True)
With ctlHello
.Caption = "Say Hello"
.Tag = "meHello"
.OnAction = "TestAction"
.Visible = True
End With

End Sub

Public Function TestAction()
MsgBox "Hello"
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top