ThisWorkbook Macros showing up in External Excel Spreadsheets

lnagel

Board Regular
Joined
May 28, 2018
Messages
117
I think I have an idea on what the issue is - If someone could verify - Much Appreciated as I dont want to break anything by changing stuff that I'm not sure on.

I have created quite a bit of code for a Project using the default Work Book Name of "ThisWorkbook"

The issue I am am seeing is that when I have both a Project Workbook open and a completely separate External Workbook open - I am seeing my Project code show up in the non related External Workbook.

This is the code in question :

Code:
Private Sub Workbook_Open()
Dim mymenubar As CommandBar
Dim newmenu As CommandBarPopup
Dim ctrl1, ctrl2, ctrl3, ctrl4, ctrl5 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
' Main Menu Options______________________________________________________________________________________________
Set ctrl1 = newmenu.Controls.Add(Type:=msoControlButton, ID:=1)
    With ctrl1
        .caption = "Save This Set As...."
        .Style = msoButtonCaption
        .OnAction = "'" & ThisWorkbook.Name & "'!saveas"
    End With
Set ctrl2 = newmenu.Controls.Add(Type:=msoControlButton, ID:=1)
    With ctrl2
        .caption = "Print Set - All Values"
        .Style = msoButtonCaption
        .OnAction = "'" & ThisWorkbook.Name & "'!printall"
    End With
Set ctrl3 = newmenu.Controls.Add(Type:=msoControlButton, ID:=1)
    With ctrl3
        .caption = "Print Set - No Cost"
        .Style = msoButtonCaption
        .OnAction = "'" & ThisWorkbook.Name & "'!printnocost"
    End With
Set ctrl4 = newmenu.Controls.Add(Type:=msoControlButton, ID:=1)
    With ctrl4
        .caption = "Import - Update Price Guide"
        .Style = msoButtonCaption
        .OnAction = "'" & ThisWorkbook.Name & "'!importprice"
    End With
Set ctrl5 = newmenu.Controls.Add(Type:=msoControlButton, ID:=1)
     With ctrl5
        .caption = "Import - Update Setbilder Version"
        .Style = msoButtonCaption
        .OnAction = "'" & ThisWorkbook.Name & "'!importset"
    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

When I have both a Project Workbook open and an External Wookbook open - I am seeing the Custom Menu (code above) show up in the External Workbook also.

I suspect that I either need to (either now OR should have done in the beginning of the project) Change the Default Name in Workbook Properties to something unique.

If you can verify that this is correct - would you know whether or not I will break things by changing it now.

Many thanks for any/all suggestions on this.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

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