![]() |
Adding multiple menu Items. Problems handling the click events
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.Active MenuBar() 'verify that menu does not exist and remove it if it does newmenu = Me.Application.ActiveExplorer.CommandBars.ActiveMe nuBar _ .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.msoCont rolPopup, 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.msoControl Button, , , Befo=1, Temporary:=True) MenuItem2 = menu.Controls.Add(Office.MsoControlType.msoControl Button, , , Befo=2, Temporary:=True) MenuItem3 = menu.Controls.Add(Office.MsoControlType.msoControl Button, , , Befo=3, Temporary:=True) MenuItem4 = menu.Controls.Add(Office.MsoControlType.msoControl Button, , , Befo=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 |
Adding multiple menu Items. Problems handling the click events
This example works http://www.vboffice.net/sample.html?...cmd=showite m -- Best regards Michael Bauer - MVP Outlook : Outlook Categories? Category Manager Is Your Tool : VBOffice Reporter for Data Analysis & Reporting : http://www.vboffice.net/product.html?pub=6&lang=en Am Mon, 6 Apr 2009 09:01:01 -0700 schrieb 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.Active MenuBar() 'verify that menu does not exist and remove it if it does newmenu = Me.Application.ActiveExplorer.CommandBars.ActiveMe nuBar _ .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.msoCont rolPopup, 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.msoControl Button, , , Befo=1, Temporary:=True) MenuItem2 = menu.Controls.Add(Office.MsoControlType.msoControl Button, , , Befo=2, Temporary:=True) MenuItem3 = menu.Controls.Add(Office.MsoControlType.msoControl Button, , , Befo=3, Temporary:=True) MenuItem4 = menu.Controls.Add(Office.MsoControlType.msoControl Button, , , Befo=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 |
All times are GMT +1. The time now is 11:14 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com