I want to create command buttons dynamicaly during runtime and call a Sub in a Module from the Tag of the Button. The button is connected to a class module from which I want to call the Sub.
For context: UF is the Userform and insxBU is defined as MSForms.CommandButton
This is the call of the Sub that creates the command button
Call SUxinsxBU(UF, "BUxLIxmak", 60, 12, 114, 18, "Neue Linie erstellen", "SUxLIxmak")
This is the Sub that creates the command button
Option Explicit
Sub SUxinsxBU(insxBUxTA, insxBUxNA, insxBUxPOxTop, insxBUxPOxLeft, insxBUxPOxWidth, insxBUxPOxHeight, insxBUxCA, insxBUxTG)
Set UF.insxBU = insxBUxTA.Controls.Add("Forms.CommandButton.1", insxBUxNA)
With UF.insxBU
.Top = insxBUxPOxTop
.Left = insxBUxPOxLeft
.Width = insxBUxPOxWidth
.Height = insxBUxPOxHeight
.Caption = insxBUxCA
.Tag = insxBUxTG
End With
' Adds Code
Set UF.insxCMxcon = New CMxcon
Set UF.insxCMxcon.CMxEV = UF.insxBU
UF.insxBUxCL.Add UF.insxCMxcon
End Sub
This is the code connected to the button
Option Explicit
Dim a As String
Public WithEvents CMxEV As MSForms.CommandButton
Private Sub CMxEV_click()
a = UF.ActiveControl.Tag
Call a
End Sub
I want to call the Sub by the name that is stored as String in the Tag of the command button. The Sub is in a module. Is that even possible?