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
Remarque :
TypeControl peut s'appliquer à tous les contrôles contenus dans une Userform chargée ou non.
Property Let TypeControl(oObjet As Object, NameContainer As String, 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
If NameContainer = vbNullString Then
CallByName cTypeControl, NamePropriete, VbLet, ValuePropriete
Else
On Error Resume Next
If StrComp(cTypeControl.Container, NameContainer, vbTextCompare) = 0 Then
If Err = 0 Then CallByName cTypeControl, NamePropriete, VbLet, ValuePropriete
End If
End If
End If
Next
Set cTypeControl = Nothing
End Property
Remarque :
pour l'utiliser :
TypeControl(Me, vbNullString, "picturebox", "picture") = Nothing
TypeControl(Me, "", "checkbox", "value") = 0
TypeControl(Me, "Frame1", "Textbox", "Text") = vbNullString
On mettra vbnullstring ou "", pour que tous les contrôles de la feuille soient modifiés. On indiquera le "Conteneur", (Frame1), pour modifier que ceux contenus dans ce dernier.