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
| Private Sub CommandButton1_Click()
Dim NextLine As Long
Dim Code As String
Dim oole As Object
Dim i As Integer
Dim L As Single, T As Single, h As Single, W As Single
'Ajouter bouton
For i = 2 To 4
L = 450
T = 120 * i
W = 300
h = 20
Set oole = ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False, _
DisplayAsIcon:=False, Left:=L, Top:=T, Width:=W, Height:=h)
oole.Name = "boutton" & i
Next i
'Ajouter le code du bouton
Code = "Private Sub Bouton1_Click()" & vbCrLf
Code = Code & " [A1].Value=""TEST" & vbCrLf
Code = Code & "End Sub"
With ThisWorkbook.VBProject.VBComponents(Feuil2.Name).CodeModule
NextLine = .CountOfLines + 1
.InsertLines NextLine, Code
End With
End Sub |
Partager