Property Let TypeControl(oObjet As Object, NameControl As String, _
NamePropriete As String, ValuePropriete As Variant)
' DONNE UNE VALEUR A UNE PROPRIETE A L'ENSEMBLE D'UN TYPE DE CONTROLE
Dim cTypeControl As Control
For Each cTypeControl In oObjet.Controls
If StrComp(TypeName(cTypeControl), NameControl, vbTextCompare) = 0 Then
CallByName cTypeControl, NamePropriete, VbLet, ValuePropriete
End If
Next
Set cTypeControl = Nothing
End Property
' TEST
'
' Mettre une Frame (frame1) dans une userform (UserForm1)
' Remplir la Frame et l'UserForm avec des checkbox et textbox
' Mettre 2 boutons
Private Sub CommandButton1_Click()
'Seules les éléments de Userform1.Frame1 sont concernés
'(on pourrait aussi écrire Me.Frame1 si Me = Userform1)
'Coche toutes les checkbox
TypeControl(UserForm1.Frame1, "checkbox", "value") = 1
'Rempli toutes les textbox
TypeControl(UserForm1.Frame1, "textbox", "text") = "Frame1"
End Sub
Private Sub CommandButton2_Click()
' Me = toute la Userform1
'Vide les checkbox et les textbox
TypeControl(Me, "checkbox", "value") = 0
TypeControl(Me, "textbox", "text") = vbNullString
End Sub