A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Adding multiple menu Items. Problems handling the click events



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old April 6th 09, 05:01 PM posted to microsoft.public.outlook.program_vba
RBAiras
external usenet poster
 
Posts: 2
Default 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

  #2  
Old April 6th 09, 08:29 PM posted to microsoft.public.outlook.program_vba
Michael Bauer [MVP - Outlook]
external usenet poster
 
Posts: 1,885
Default 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

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add a menu item to AppointmentItem's right-click menu? OctopusThu Add-ins for Outlook 6 January 25th 07 06:43 PM
Adding Multiple events in Outlook rickree Outlook - Calandaring 1 November 13th 06 11:19 PM
Best strategy for handling events in outlook danikenan Add-ins for Outlook 3 October 16th 06 06:12 AM
Outlook 2000 is crashing while adding right click context menu. Vinayakc Add-ins for Outlook 0 August 17th 06 04:08 PM
Item open events and double click events in exchange client extension. Fanxa Add-ins for Outlook 1 August 9th 06 08:18 AM


All times are GMT +1. The time now is 05:05 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-2025 Outlook Banter.
The comments are property of their posters.