bonjour j ai un probleme sur Excel VBA
j ai cree des Checkbox dynamique sur mon userform. le nombre et le nom varie en fonction d une variable
Code :
- Set Checkbox = Me.Controls.Add("forms.Checkbox.1" )
- With Checkbox
- .Name = "CheckBox_" & Info
- .Caption = Info
- .Value = Statut
- .Left = 142
- .Top = Info_Pro_Position + 15 * Info_Pro_Number
- .Width = 200
- .Enabled = True
|
dans cet userform , j ai creer unb bouton valider qui me permet de transferer les valeurs des Checkbox sur excel.
Code :
- Private Sub BNT_Validate_Click()
- Column_Nombre = Sheets("Commandes" ).Range("A1" ).End(xlToRight).Column
- 'transferer les valeurs sur Excel
- For X = 2 To Column_Nombre
- Info = Sheets("Commandes" ).Cells(1, X)
- Checkbox_Name = "CheckBox_" & Info
- Value = Controls.Item(Checkbox_Name).Value
- Sheets("Commandes" ).Cells(2, X) = Value
- Next X
- 'fermer la fenetre
- Unload UserForm_Setting
- End Sub
|
C ets a ce moment que j ai un probleme, Excel m affiche qu il ne reconnait pas le nom de ma checkbox. J ai donc differente hypotheses :
- je ne sais pas comment "activer" les checkbox pour que je puisse y acceder a partir de Private Sub BNT_Validate_Click()
- je ne connais pas le ligne de code pour trouver le nom de la checkbox dynamique
- autre chose..
je vous donne le code complet pour avoir une vision d ensemble plus claire
Private Sub UserForm_Initialize()
Code :
- Column_Nombre = Sheets("Commandes" ).Range("A1" ).End(xlToRight).Column
-
- 'Creer les checkbox pour Info Perso
- ' creer le label Info perso
- Info_Perso_Position = 15
- Set Label = Me.Controls.Add("forms.Label.1" )
- With Label
- .Name = "Label_Perso_Info"
- .Caption = "Personnal Information"
- .Left = 12
- .Top = Info_Perso_Position
- .Width = 200
- End With
- Info_Perso_Number = 1
- 'Creer les checkbox pour Info Perso
- For X = 1 To Column_Nombre
- 'calcul des variables
- Statut = Sheets("Commandes" ).Cells(2, X)
- Info_Type = Sheets("Commandes" ).Cells(3, X)
- Info = Sheets("Commandes" ).Cells(1, X)
-
- If Info_Type = "Perso" Then
- Dim Checkbox As Object
- Set Checkbox = Me.Controls.Add("forms.Checkbox.1" )
- With Checkbox
- .Name = "CheckBox_" & Info
- .Caption = Info
- .Value = Statut
- .Left = 24
- .Top = Info_Perso_Position + 15 * Info_Perso_Number
- .Width = 200
- .Enabled = True
- End With
- Info_Perso_Number = Info_Perso_Number + 1
- End If
- Next X
- 'Creer les checkbox pour Info Pro
- Info_Pro_Position = 15
- Set Label = Me.Controls.Add("forms.Label.1" ) ' creer le label Info Pro
- With Label
- .Name = "Label_Prof_Info"
- .Caption = "Professional Information"
- .Left = 130
- .Top = Info_Pro_Position
- .Width = 200
- End With
-
- Info_Pro_Number = 1
- For X = 1 To Column_Nombre 'Creer les checkbox pour Info Pro
- 'calcul des variables
- Statut = Sheets("Commandes" ).Cells(2, X)
- Info_Type = Sheets("Commandes" ).Cells(3, X)
- Info = Sheets("Commandes" ).Cells(1, X)
-
- If Info_Type = "Pro" Then
- Set Checkbox = Me.Controls.Add("forms.Checkbox.1" )
- With Checkbox
- .Name = "CheckBox_" & Info
- .Caption = Info
- .Value = Statut
- .Left = 142
- .Top = Info_Pro_Position + 15 * Info_Pro_Number
- .Width = 200
- .Enabled = True
- End With
- Info_Pro_Number = Info_Pro_Number + 1
- End If
- Next X
- End Sub
- Private Sub BNT_Validate_Click()
- Sheets("Commandes" ).Activate
- Column_Nombre = Sheets("Commandes" ).Range("A1" ).End(xlToRight).Column
- 'transferer les valeurs sur Excel
- For X = 2 To Column_Nombre
- Info = Sheets("Commandes" ).Cells(1, X)
- Checkbox_Name = "CheckBox_" & Info
- Value = Controls.Item(Checkbox_Name).Value
- Sheets("Commandes" ).Cells(2, X) = Value
- Next X
- 'fermer la fenetre
- Unload UserForm_Setting
- End Sub
|
J espere que vous pourrez me donner des bons conseils.
A bientot