Adding multiple menu Items. Problems handling the click events

R

RBAiras

I’ve added a new menu bar with four buttons to Outlook using the code shown
below (VB code). When it runs, MenuItem1 successfully runs Public sub
MenuItem1_Click(). But when I click any of the other buttons, (MenuItem2,
MenuItem3, or MenuItem4) instead of calling their respective sub(), they
execute all the sub’s assigned to the other buttons MenuItem2_Click,
MenuItem3_Click, and MenuItem4_Click, always starting in that order, as if
there was a single sub() instead of three.
What am I doing wrong?
This is the code I use to add the menu bar and its buttos,
VB code:
Private Sub AddMenuBar()

'Get the menu bar in the explorer window.
menuBar = Me.Application.ActiveExplorer().CommandBars.ActiveMenuBar()
'verify that menu does not exist and remove it if it does
newmenu = Me.Application.ActiveExplorer.CommandBars.ActiveMenuBar _
.FindControl(Office.MsoControlType.msoControlPopup, , "Calendarios
de R y D", True, True)
If newmenu IsNot Nothing Then
newmenu.Delete(True)
End If


'Add new menu
menu = menuBar.Controls.Add(Office.MsoControlType.msoControlPopup,
Temporary:=False)
If menu IsNot Nothing Then
'edit the menu properties
menu.Caption = "Calendarios de R y D"
menu.Tag = "Calendarios de R y D"
'add a submenu to the menu and set its properties

MenuItem1 =
menu.Controls.Add(Office.MsoControlType.msoControlButton, , , Before:=1,
Temporary:=True)
MenuItem2 =
menu.Controls.Add(Office.MsoControlType.msoControlButton, , , Before:=2,
Temporary:=True)
MenuItem3 =
menu.Controls.Add(Office.MsoControlType.msoControlButton, , , Before:=3,
Temporary:=True)
MenuItem4 =
menu.Controls.Add(Office.MsoControlType.msoControlButton, , , Before:=4,
Temporary:=True)



With MenuItem1

.Style = Office.MsoButtonStyle.msoButtonIconAndCaption
.Caption = "Calculate Baby's Calendar"
.FaceId = 65
.Tag = "Tag Cloud Submenu"
'.OnAction = "MenuItem1_Click"
End With
With MenuItem2
.Style = Office.MsoButtonStyle.msoButtonIconAndCaption
.Caption = "Calculate Diane's Responsibilities"
.FaceId = 66
.Tag = "Otra nube"
'.OnAction = "MenuItem2_Click"
End With
With MenuItem3
.Style = Office.MsoButtonStyle.msoButtonIconAndCaption
.Caption = "Free Diane's Unmovables"
.FaceId = 65
.Tag = "Otra nube"
'.OnAction = "MenuItem3_Click"
End With
With MenuItem4
.Style = Office.MsoButtonStyle.msoButtonIconAndCaption
.Caption = "Create Diane's Unmovables"
.FaceId = 65
.Tag = "Otra nube"
'.OnAction = "MenuItem4_Click"
End With





'Add an event handler to the menu item
AddHandler MenuItem1.Click, AddressOf MenuItem1_Click
AddHandler MenuItem2.Click, AddressOf menuItem2_Click
AddHandler MenuItem3.Click, AddressOf menuItem3_Click
AddHandler MenuItem4.Click, AddressOf menuItem4_Click

'Display the new menu
menu.Visible = True

End If





End Sub
 

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