Adding multiple menu Items. Problems handling the click events

Status
Not open for further replies.
U

UkJBaXJhcw

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
 

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
This example works

http://www.vboffice.net/en/developers/create-new-commandbar-with-one-button

Best regards

Michael Bauer

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.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
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
C Outlook 2007 Removing then adding account restores junk email processing Using Outlook 0
J O365 - Adding Shared Google Calendar ICS link issue in O365 Using Outlook 0
B Adding signature to bottom of VBA reply email Outlook VBA and Custom Forms 1
S User Defined Fields adding new value (2) Using Outlook 0
M Changing the preferred order for "Put this entry in" list for adding new contacts to the Address Book Using Outlook 1
M Adding Subject to this Link-Saving VBA Outlook VBA and Custom Forms 5
E Project Management - Adding Folders for Different Folder Types Using Outlook.com accounts in Outlook 0
D Adding Enterprise Exchange Email Account to Outlook Prevents Sending via Outlook.com Account Using Outlook.com accounts in Outlook 10
S Adding new Exchange (2016) rule very slow down Microsoft Outlook Exchange Server Administration 0
Z Outlook Custom Form: Adding Dropdown(Project Code) at the end of subject Outlook VBA and Custom Forms 0
Z Adding dropdown list using custom form Outlook VBA and Custom Forms 7
M Adding Macro to populate "to" "subject" "body" not deleting email string below. Outlook VBA and Custom Forms 5
E Unable to open Outlook 2010 after adding new email account Using Outlook 4
O Adding a new account - "CompanyL (none)" line is added Using Outlook 5
broadbander Needing help with reply/reply all while keeping attachments and adding a new CC recipient. Outlook VBA and Custom Forms 5
M adding corresponding contact form data on a mass scale Using Outlook 5
A VB to "reply all" email items stored in a folder of outlook with adding a new message Outlook VBA and Custom Forms 0
K adding more rules to 'different domains check' macro Outlook VBA and Custom Forms 2
P MS OUTLOOK 2013 - Adding Sender on the CC line Using Outlook 5
R User Defined Fields adding new value Using Outlook 3
W Adding A Macro To Message Ribbon Outlook VBA and Custom Forms 2
I Collecting mail address from GAB and adding to Outlook Task Using Outlook 2
A Outlook 2016 - adding outlook.com account creates a new/strange address Using Outlook.com accounts in Outlook 18
F Adding textbox filter to listbox? Outlook VBA and Custom Forms 2
N Recurring invite sent w/distribution list adding/removing attendees Using Outlook 0
J Issues with adding iCloud to Outlook Using Outlook 1
G Adding a contact to Outlook with a custom form using Access VBA Outlook VBA and Custom Forms 1
C Macro to send email after changing from address and adding signature Outlook VBA and Custom Forms 1
J Adding Reply & Delete to main toolbar? Using Outlook 0
T Outlook 2007 adding categories Using Outlook 15
N Adding Appointment Item in Outlook to Shared Calendar Folder Outlook VBA and Custom Forms 7
Diane Poremsky Adding Emojis to Outlook's AutoCorrect Using Outlook 0
T Adding "Mark As Complete" btton to Task Remindet Pop-Up Using Outlook 3
O Saving Attachments to folder on disk and adding Initials to end of file name Outlook VBA and Custom Forms 9
Ascar_CT Adding contacts on Android phone and then syncing them to Outlook Using Outlook.com accounts in Outlook 4
A Adding a 2010 sharepoint contact list to outlook 2010 address book Using Outlook 1
M Adding fields to Task in Outlook Home and Business 2010 Outlook VBA and Custom Forms 7
S Using Send on Behalf is adding extra data in from line Using Outlook 1
Lucylou Outlook 2013 Adding Outlook.com breaks profile, "Outlook not working" messag Using Outlook.com accounts in Outlook 1
C Adding Categories when Composing Email Using Outlook 1
stephenjones Adding a business account to Outlook Using Outlook 1
Chris Grew Adding 2nd Email Address BCM (Business Contact Manager) 3
G Adding an attachment to email I just created (VBA) Outlook VBA and Custom Forms 1
tswatek Inbox problems after adding MS Exchange email Using Outlook 2
L Adding sender's e-mail to global address book DL Outlook VBA and Custom Forms 1
R Adding vba to script list Outlook VBA and Custom Forms 4
F Adding User Defined Field to another form Using Outlook 0
Edaniels Adding Week Number on Calender Using Outlook 2
I Adding appointments/tasks to other user's calendar Using Outlook 1
J Adding original email text to outlook message template Outlook VBA and Custom Forms 2

Similar threads

Top