Bonjour à tous,
Voilà je vous présente mon soucis, je souhaite créer des boutons de façon dynamique, mais je n'arrive pas à implémenter du code pour ces boutons.
Comment faire pour lancer ma fonction à partir de mon bouton ?
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 Dim Test(10) As String Dim T1 As String Dim Para, Help, Nom_Control As String Dim i, j, x, y As Integer Dim Button As MSForms.CommandButton Function Button1() MsgBox ("ça marche") End Function Private Sub UserForm_Initialize() Sheets("Base").ScrollArea = "A1:AZ50" For i = 1 To 10 If Sheets("Base").Range("B" & (i + 15)).Value = "" Then j = j + 1 Else j = j + 1 Test(i) = Sheets("Base").Range("B" & (j + 15)).Value T1 = Test(i) Nom_Control = "Forms.CommandButton.1" If i > 7 Then y = 70 + (i - 2) * 40 Else y = 70 + (i - 1) * 40 End If Set Button = Me.Controls.Add(Nom_Control) With Button .Top = y .Left = 100 .Height = 30 .Width = 210 .Caption = T1 .Visible = True .ForeColor = &H80000012 .BackStyle = fmBackStyleTransparent .PicturePosition = fmPicturePositionAboveCenter .TabIndex = 0 .Name = "CommandButtonDetail_" & i .OnAction = "'Button1'" ''--> c'est ici que ça coince End With End If Next i Sheets("Base").ScrollArea = "A1:AK24" End Sub
Merci d'avance !
Partager