Tag different module

nada

Board Regular
Joined
Jul 4, 2006
Messages
193
I have two different modules in my code. In module I create buttons and give them a tag so that I know which buttons that has been pressed. When a button is pressed the .onAction runs and calls a sub. in that sub i want to check which button that was in fact pressed by checking the tag. however i do not know how to write the code for that when the tag is assigned in a different module. Please help me with this code! My code in the module where I create the buttons is:

Sub Create_Menu()
Dim stapelDiagramKnapp As CommandBarButton
Set stapelDiagramKnapp = .Controls.Add(Type:=msoControlButton)
With stapelDiagramKnapp
.Tag = "stapel"
.BeginGroup = True
.OnAction = "ChartModul1.arrayLoop"
end with

and in the sub in the module ChartModul1:
Sub arrayLoop()
Dim cmdBtn As CommandBarButton
Set cmdBtn = Meny.CommandBars.ActionControl

If cmdBtn.Tag = "stapel" Then
MsgBox ("Tag = stapel")
End If
I guess I have it wrong on the Set cmdBth line but I do not know how to write it. Please help me! Thanks very much!
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
In the Object Browser search for ActionControl, click it and press F1. Help contains an example just like yours.
 
Upvote 0
Hello Andrew! Thanks for your tip! I tried using that code but as I said in my question I do not think it works since I have the codes in different modules. What do I have to change in order for it to work? It seems like very good code but I do not get any messageboxes so I guess the code does not get any tags. Please help me ou! Thank you very much!
 
Upvote 0
Please post your actual code. Your Create_Menu code wouldn't compile because there is no qualifier for the first dot in:

Set stapelDiagramKnapp = .Controls.Add(Type:=msoControlButton)
 
Upvote 0

Forum statistics

Threads
1,224,889
Messages
6,181,611
Members
453,056
Latest member
apmale77

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