kapela2017
New Member
- Joined
- Oct 16, 2022
- Messages
- 34
- Office Version
- 365
- Platform
- Windows
Greetings gentlemen, I found this code, and the truth is that it works very well, it is a class module that creates a matrix for different controls (textboxes, combobox, listbox, etc.) it is really very versatile since you can assign different events For each control, what I'm trying to do is manage to exclude two textboxes (textbox1 and textbox2) from the matrix but I don't know how to do it, if someone can give me an idea I appreciate it, I'll be attentive to any contribution....
VBA Code:
'Inside the class module
Private m_PassedControl As MSForms.Control
Private WithEvents chk As MSForms.CheckBox
Private WithEvents cbo As MSForms.ComboBox
Private WithEvents lst As MSForms.ListBox
Private WithEvents opt As MSForms.OptionButton
Private WithEvents spn As MSForms.SpinButton
Private WithEvents txt As MSForms.TextBox
Property Set ctl(PassedControl As MSForms.Control)
Set m_PassedControl = PassedControl
Select Case TypeName(PassedControl)
Case "CheckBox"
Set chk = PassedControl
Case "ComboBox"
Set cbo = PassedControl
Case "ListBox"
Set lst = PassedControl
Case "OptionButton"
Set opt = PassedControl
Case "SpinButton"
Set spn = PassedControl
Case "TextBox"
Set txt = PassedControl
End Select
End Property
Private Sub cbo_Change()
PrintControlName
End Sub
Private Sub chk_Click()
PrintControlName
End Sub
Private Sub lst_Change()
PrintControlName
End Sub
Private Sub opt_Click()
PrintControlName
End Sub
Private Sub spn_Change()
PrintControlName
End Sub
Private Sub txt_Change()
PrintControlName
End Sub
Sub PrintControlName()
Debug.Print m_PassedControl.Name
End Sub
'Inside the userform
Public collControls As Collection
Private cMultipleControls As clsMultipleControls
Private Sub UserForm_Activate()
Dim ctl As MSForms.Control
Set collControls = New Collection
For Each ctl In Me.Controls
Set cMultipleControls = New clsMultipleControls
Set cMultipleControls.ctl = ctl
collControls.Add cMultipleControls
Next ctl
End Sub