Add-ins MenuBar Duplicates in Drop Down when opening multiple copies of existing workbook

lnagel

Board Regular
Joined
May 28, 2018
Messages
117
I have an Add-ins Menu Bar (which works fine) defined and processed in "ThisWorkbook" using the code below:

The issue is that I need to have multiple copies of this workbook open at the same time.

To get multiple copies of the workbook I copy the original existing workbook save it as a different filename

So now 2 different workbooks with 2 different file names

When I open both workbooks - Each one shows the Add-ins menu but when I click on either Add-ins menu - I see duplicate Menus and duplicate CTRLs within those menus

If open 3 of the workbooks - I see 3 of the Menu items and 3 sets of CTRLs

Anyone please?

Code:
Private Sub Workbook_Open()
Dim mymenubar As CommandBar
Dim newmenu As CommandBarPopup
Dim ctrl1, ctrl2 As CommandBarButton
   
Set mymenubar = Application.CommandBars("Worksheet menu Bar")
Set newmenu = mymenubar.Controls.Add(Type:=msoControlPopup, Temporary:=True, before:=2)
'newmenu.caption = "SetBilder-1955 Topps"
mymenubar.Visible = True
        
Set ctrl1 = newmenu.Controls.Add(Type:=msoControlButton, ID:=1)
     With ctrl1
        .caption = "Import Set"
        .Style = msoButtonCaption
        .OnAction = "'" & ThisWorkbook.Name & "'!importset"
    End With
    
Set ctrl2 = newmenu.Controls.Add(Type:=msoControlButton, ID:=1)
    With ctrl2
        .caption = "Import Price Guide"
        .Style = msoButtonCaption
        .OnAction = "'" & ThisWorkbook.Name & "'!importprice"
    End With
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim CmdBar As CommandBar
Dim CmdBarMenu As CommandBarControl
On Error Resume Next
Set CmdBar = Application.CommandBars("Worksheet Menu Bar")
Set CmdBarMenu = CmdBar.Controls("SetBuilder")
CmdBarMenu.Delete
Set CmdBarMenu = CmdBar.Controls("SetBilder")
CmdBarMenu.Delete
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Try adding this at the start - if it finds the menu already exists, it won't recreate it:
Code:
For n = 1 To Application.CommandBars("Worksheet menu Bar").Controls.Count
  If Application.CommandBars("Worksheet menu Bar").Controls (n).Caption = "SetBilder-1955 Topps" Then End
Next n
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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