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
|
Sub ma_procedure()
...1000 lignes de code...
End Sub
Sub ma_macro()
...code...
'Ajout CommandButton1 dans la feuille
Set Obj = s.OLEObjects.Add("Forms.CommandButton.1")
With Obj
.Left = 550 'position horizontale
.Top = 100 'position verticale
.Width = 180 'largeur
.Height = 30 'hauteur
.Object.BackColor = RGB(235, 235, 200) 'Couleur de fond
.Object.Caption = "Bouton1"
End With
'Paramètres pour la création de la macro:
laMacro = "Sub CommandButton1_Click()" & vbCrLf
laMacro = laMacro & "ma_procedure" & vbCrLf
laMacro = laMacro & "End Sub"
With ThisWorkbook.VBProject.VBComponents(ActiveSheet.Name).CodeModule
x = .CountOfLines + 1
.InsertLines x, laMacro
End With
...code... |