Bonjour à tous,

Et je remercie par avance ceux qui pourront me donner des pistes.

Je souhaite créer une interface sans que l'utilisateur puisse manipuler la feuille Excel.

Pour cela j'ai créé un Userform en plein écran qui va générer 100 boutons de commandes dont les propriétés Caption et BackColor dépendront de données cachées dans la feuille Excel. Les données sont dans les colonnes A à E, ligne 1 à 100 de la feuille 1.

Mon souci : Comment associé une action à l'évenement :
"commandbutton._click ()" pour les boutons générés?

Quand l'utilisateur clicquera sur un des 100 boutons créés je souhaiterai par exemple enregistrer la valeur "Caption" du bonton de commande dans une cellule spécifique.

Voilà j'espère avoir été clair

Amicalement,
ThamAL

Voici le code pour le moment (L'userform dans le mode création est vide)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
 
Private Sub UserForm_Activate()
With Me
.StartUpPosition = 3
.Width = Application.Width
.Height = Application.Height
.Left = 0
.Top = 0
End With
 
For i = 1 To 100
 
Dim Obj As Control
Set Obj = Me.Controls.Add("forms.commandbutton.1")
 
With Obj
.Caption = Sheets("feuil1").Range("a" & i)
If Range("e" & i).Value = 1 Then
.BackColor = &H80FF80
Else
If Range("e" & i).Value = 2 Then
.BackColor = &H8080FF
Else
If Range("e" & i).Value = 3 Then
.BackColor = &HFFFF80
Else
If Range("e" & i).Value = 4 Then
.BackColor = &H80FFFF
Else
.BackColor = &H80FF&
End If
End If
End If
End If
 
If i < 21 Then
a = 60 * i
.Left = a - 50
.Top = 30
.Width = 50
.Height = 20
 
Else
 
If i > 20 And i < 41 Then
a = 60 * (i - 20)
.Left = a - 50
.Top = 60
.Width = 50
.Height = 20
 
Else
If i > 40 And i < 61 Then
a = 60 * (i - 40)
.Left = a - 50
.Top = 90
.Width = 50
.Height = 20
 
Else
If i > 60 And i < 81 Then
a = 60 * (i - 60)
.Left = a - 50
.Top = 120
.Width = 50
.Height = 20
 
Else
If i > 80 Then
a = 60 * (i - 80)
.Left = a - 50
.Top = 150
.Width = 50
.Height = 20
 
End If
End If
End If
End If
End If
 
End With
 
Next i
 
End Sub