How can the info from a class event be used as an argument for a Sub in a userform?
In this example, there are multiple command buttons in a form, and 1 class module for all buttons. I want to write the Name of the command button, to a cell in Excel. The code to write to Excel must be in the form.
My attempt to transfer the info is by "Call ThisSubInForm(MyButton.Name)" but it won't work.
MODULE CODE
Option Explicit
Sub Form_OzG()
UserFormOG.Show vbModeless
End Sub
FORM CODE
Dim colButtons As New Collection
Private Sub UserForm_Initialize()
Dim ctl As MSForms.Control
Dim obEvents As clsButtons
For Each ctl In Me.Controls
If TypeOf ctl Is MSForms.CommandButton Then
Set obEvents = New clsButtons
Set obEvents.MyButton = ctl
colButtons.Add obEvents
End If
Next ctl
End Sub
Private Sub ThisSubInForm(Btn As String)
Range("C4") = Btn
End Sub
CLASS MODULE
Public WithEvents MyButton As MSForms.CommandButton
Private Sub MyButton_Click()
' Call ThisSubInForm(MyButton.Name)
Msgbox "You have clicked " & MyButton.Name
End Sub
Bookmarks