VBA: combined custom-menu for multiple Add-Ins

Cornerback

New Member
Joined
Mar 20, 2013
Messages
4
Hi everyone,

I'm looking for a solution for the following problem. Any help would be appreciated <3

I have two Add-Ins, which both create an entry in a custom-menu on startup:


No 1:
Code:
Set MenuObject = Application.CommandBars(1). _
                    Controls.Add(Type:=msoControlPopup, _
                    Before:=10, _
                    Temporary:=True)
                MenuObject.Caption = "Auswertung"
                
Set MenuItem2 = MenuObject.Controls.Add(Type:=msoControlPopup)
               MenuItem2.Caption = "MCM"
               MenuItem2.BeginGroup = True
Set SubMenuItem2 = MenuItem2.Controls.Add(Type:=msoControlButton)
                SubMenuItem2.Caption = "Auswerten"
                SubMenuItem2.FaceId = 48
                SubMenuItem2.OnAction = "AuswahlForm"

No 2:

Code:
Set MenuObject = Application.CommandBars(1). _
                    Controls.Add(Type:=msoControlPopup, _
                    Before:=10, _
                    Temporary:=True)
                MenuObject.Caption = "Auswertung"
                
Set MenuItem1 = MenuObject.Controls.Add(Type:=msoControlPopup)
               MenuItem1.Caption = "EvoCS"
Set SubMenuItem1 = MenuItem1.Controls.Add(Type:=msoControlButton)
                SubMenuItem1.Caption = "SA-Admin"
                SubMenuItem1.FaceId = 53
                SubMenuItem1.OnAction = "DummyMacro"

Now the following is to be done:

  • If both Add-Ins are installed, both MenuObject.Controls ("EvoCS" and "MCM") have to be sub-menus of "Auswertung"
  • If one Add-In is uninstalled, the MenuObject of the Add-In is removed, while the other one isnt changed.
  • If both are uninstalled, the custom-menu "Auswertung" should also be removed

In my current version, each Add-In created it's own "Auswertung"-custom-menu, but I did not yet manage to merge both menus. Any ideas?

Kind regards,

Thorben
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi and thanks.

I already used the Installed-property to check if they are installed. The problem is, that i have no idea how to merge the two menus (one created by each addon) into one menu containing submenus for both addons...
 
Upvote 0
It sounds as though you just need to alter the code in each one to:
1. Loop through the controls on Application.Commandbars(1) and test if the caption is "Auswertung" and then only add it if it's not already present
2. When closing test if there is more than one control on the Auswertung menu - if so, only remove the control the add-in created; if not, delete the Auswertung control itself.
 
Upvote 0
Looping through seems to work now. however, if the first addin created the MenuObject, and the second addin does not create another one, how can i "access" the MenuObject created by the first addin? right now i get an error because there is no MenuObject für addon 2 :/
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,814
Members
449,339
Latest member
Cap N

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top