AW: Aktion für viele Buttons zusammenfassen
20.10.2019 12:46:43
Nepumuk
Hallo,
im Modul des Userforms:
Option Explicit
Private mobjCommandButtonClassCollection As Collection
Private Sub UserForm_Initialize()
Dim objCommandButtonClass As clsCommandButton
Dim objControl As MSForms.Control
Set CommandButtonClassCollection = New Collection
For Each objControl In Controls
If TypeOf objControl Is MSForms.CommandButton Then
Set objCommandButtonClass = New clsCommandButton
Set objCommandButtonClass.CommandButton = objControl
Call CommandButtonClassCollection.Add(Item:=objCommandButtonClass)
Set objCommandButtonClass = Nothing
End If
Next
End Sub
Private Sub UserForm_Terminate()
Set CommandButtonClassCollection = Nothing
End Sub
Private Property Get CommandButtonClassCollection() As Collection
Set CommandButtonClassCollection = mobjCommandButtonClassCollection
End Property
Private Property Set CommandButtonClassCollection(ByRef probjCommandButtonClassCollection As Collection)
Set mobjCommandButtonClassCollection = probjCommandButtonClassCollection
End Property
In einem Klassenmodul mit dem Namen "clsCommandButton":
Option Explicit
Private WithEvents mobjCommandButton As MSForms.CommandButton
Private Sub Class_Terminate()
Set CommandButton = Nothing
End Sub
Private Sub mobjCommandButton_Click()
MsgBox CommandButton.Name 'Hier kommt dein Code
End Sub
Friend Property Get CommandButton() As MSForms.CommandButton
Set CommandButton = mobjCommandButton
End Property
Friend Property Set CommandButton(ByRef probjCommandButton As MSForms.CommandButton)
Set mobjCommandButton = probjCommandButton
End Property
Gruß
Nepumuk