Refer to another module tag  
Author Message
AndersBank





PostPosted: Visual Basic for Applications (VBA), Refer to another module tag Top

I have a small problem that is of greate importance to me and seem to have a hard time getting any help. I have two modules. in the first module i have code that creates buttons. if a button is pressed then a sub in ANOTHER module is called. that works fine. in that sub i want to check which button has been pressed. therefore i need to look at the tag for the button. it is here that my code fails. i do not know how to do this when the button is created in another module than the sub. that is all i am asking. My code for the first module:

Public Sub Create_Menu()
Dim MyBar As CommandBar
Dim MyPopup As CommandBarPopup
Dim linjeDiagramKnapp As CommandBarButton
Dim stapelDiagramKnapp As CommandBarButton
'stapeldiagramknapp
Set stapelDiagramKnapp = .Controls.Add(Type:=msoControlButton)
With stapelDiagramKnapp
.Tag = "stapel"
.Caption = "Stapeldiagram"
.Style = msoButtonCaption
''' msoButtonAutomatic, msoButtonIcon, msoButtonCaption,
''' or msoButtonIconandCaption
.BeginGroup = True
.OnAction = "ChartModul1.arrayLoop"
End With
'slut stapeldiagramknapp

........some more buttons..........

in ANOTHER MODULE:

Public Sub arrayLoop()
Dim obj As Object
Dim currentChart As Object

Select Case CommandBars.ActionControl.Tag
Case "linje"
MsgBox ("linje button clicked.")
Case "stapel"
MsgBox ("stapel button clicked.")
Case ""
MsgBox ("empty")
End Select

I do not get any tag, it is always "". thus, there must be a probelm with the fact that they are in different modules. please help me! i have know idea how to write this nor how to find info that tells you how to do it. it is really important to me. any help appreciated! thanks alot!



Microsoft ISV Community Center Forums2  
 
 
Cindy Meister





PostPosted: Visual Basic for Applications (VBA), Refer to another module tag Top

Hi Anders

the Tag property is not populated "all by itself". You have to assing
the value when you create the button (or at some later point). That's
why my sample code mentioned you could also use the Caption, or any
other property that will help you clearly distinguish one button from
another.