Sub AjoutCommandButton_Feuille()
Dim Ws As Worksheet
Dim Obj As OLEObject
Dim laMacro As String
Dim x As Integer
Set Ws = ActiveWorkbook.Sheets.Add(after:=Worksheets(Worksheets.Count))
ActiveWindow.DisplayGridlines = False
'Ajout CommandButton dans la feuille
Set Obj = Ws.OLEObjects.Add("Forms.CommandButton.1")
With Obj
.Left = 369 'position horizontale
.Top = 10 'position verticale
.Width = 108 'largeur
.Height = 21 'hauteur
.Object.Caption = "Exporter vers JPG"
.Object.Font.Italic = True
.Object.Font.Size = 8
.Object.Font.Name = "Verdana"
End With
'Paramètres pour la création de la macro:
'(suppression contenu cellules)
laMacro = "Private Sub CommandButton1_Click()" & vbCrLf
laMacro = laMacro & "ExportToJpgOnglet" & vbCrLf
laMacro = laMacro & "End Sub"
With ActiveWorkbook.VBProject.VBComponents(ActiveSheet.CodeName).CodeModule
x = .CountOfLines + 1
.InsertLines x, laMacro
End With
ActiveSheet.Name = "test"
End Sub