PC Review


Reply
Thread Tools Rate Thread

Custom menu Items. Unable to assign the right sub to each button

 
 
RBAiras
Guest
Posts: n/a
 
      4th Apr 2009
I’ve added a new menu bar with four buttons to Outlook using this code shown
above (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) they execute all the sub’s assigned to the other
buttons MenuItem2_Click, MenuItem3_Click, and MenuItem4_Click, always
starting in that order.
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

 
Reply With Quote
 
 
 
 
Brian Tillman [MVP - Outlook]
Guest
Posts: n/a
 
      6th Apr 2009
"RBAiras" <(E-Mail Removed)> wrote in message
news:54C67024-8A18-4F00-BFE3-(E-Mail Removed)...

> I’ve added a new menu bar with four buttons to Outlook using this code shown
> above (VB code).


Please ask coding questions in microsoft.public.outlook.program_vba
--
Brian Tillman [MVP-Outlook]

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assign macro to custom menu =?Utf-8?B?SGFybGV5?= Microsoft Excel Programming 2 15th Nov 2006 02:55 PM
To restore menu items of context menu in IE after adding custom items vicsmith@yandex.ru Windows XP Internet Explorer 0 26th Sep 2005 03:52 AM
To restore menu items of context menu in IE after adding custom items vicsmith@yandex.ru Windows XP Internet Explorer 0 21st Sep 2005 09:58 AM
Assign Sub to Custom Button Aggie94 Microsoft Excel Programming 4 14th Aug 2004 05:50 PM
Assign macro to custom button P Sims Microsoft Excel Worksheet Functions 1 11th Aug 2003 06:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:30 AM.