Je souhaite créer un bonton en VBA dans une feuille que je viens de créer,
et ensuite associer du code a ce bouton.
J'utilise le code suivant qui me génère une erreur 9... et je ne comprend
pas pourquoi.
Le code :<<
... Dim Ma_Nouvelle_Feuille As Worksheet
Dim Mon_Bouton As OLEObject
Dim Code_Bouton As String
Dim NextLine As Long
' *** Création nouvelle feuille ***
Set Ma_Nouvelle_Feuille = Sheets.Add(, Count:=1, after:=Sheets(1))
Ma_Nouvelle_Feuille.Name = "Synthèse"
Ma_Nouvelle_Feuille.Select
' *** Mise en forme des titres ***
... du code qui marche ...
' *** Mise en place du bouton fermer ***
Set Mon_Bouton =
ActiveWorkbook.ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1",
_
Link:=False, DisplayAsIcon:=False, Left:=10, Top:=10, Width:=100,
Height:=30)
Sub Creer_Boutons() Dim cell As Range Dim BoutonCourant As Shape '----hauteur de ligne=hauteur du bouton Selection.EntireRow.RowHeight = 36 '----creer un bouton dans chaque cellule de la selection For Each cell In Selection With cell ' mettre en commentaire selon besoins ' ------Bouton rectangulaire avec biseaux Set BoutonCourant = ActiveSheet.Shapes.AddShape(msoShapeBevel, .Left, .Top, .Width, .Height) '-------Bouton Oval 'Set BoutonCourant = ActiveSheet.Shapes.AddShape(msoShapeOval, .Left, .Top, .Width, .Height) With BoutonCourant .Fill.ForeColor.SchemeColor = 10 ' rouge .Fill.BackColor.SchemeColor = 11 ' vert .Line.ForeColor.SchemeColor = 22 ' gris .OLEFormat.Object.Caption = "O" '----affecter une macro .OnAction = "Bouton_Click" .Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter End With '(caption) End With '(bouton) .Value = False '---- la cellule reçoit FAUX=bouton Rouge, VRAI=Bouton Vert End With '(cellule) DoEvents Next [a1].Select End Sub
Sub Creer_Boutons()
Dim cell As Range
Dim BoutonCourant As Shape
'----hauteur de ligne=hauteur du bouton
Selection.EntireRow.RowHeight = 36
'----creer un bouton dans chaque cellule de la selection
For Each cell In Selection
With cell
' mettre en commentaire selon besoins
' ------Bouton rectangulaire avec biseaux
Set BoutonCourant = ActiveSheet.Shapes.AddShape(msoShapeBevel, .Left, .Top, .Width, .Height)
'-------Bouton Oval
'Set BoutonCourant = ActiveSheet.Shapes.AddShape(msoShapeOval, .Left, .Top, .Width, .Height)
With BoutonCourant
.Fill.ForeColor.SchemeColor = 10 ' rouge
.Fill.BackColor.SchemeColor = 11 ' vert
.Line.ForeColor.SchemeColor = 22 ' gris
.OLEFormat.Object.Caption = "O"
'----affecter une macro
.OnAction = "Bouton_Click"
.Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With '(caption)
End With '(bouton)
.Value = False '---- la cellule reçoit FAUX=bouton Rouge, VRAI=Bouton Vert
End With '(cellule)
DoEvents
Next
[a1].Select
End Sub
Sub Creer_Boutons() Dim cell As Range Dim BoutonCourant As Shape '----hauteur de ligne=hauteur du bouton Selection.EntireRow.RowHeight = 36 '----creer un bouton dans chaque cellule de la selection For Each cell In Selection With cell ' mettre en commentaire selon besoins ' ------Bouton rectangulaire avec biseaux Set BoutonCourant = ActiveSheet.Shapes.AddShape(msoShapeBevel, .Left, .Top, .Width, .Height) '-------Bouton Oval 'Set BoutonCourant = ActiveSheet.Shapes.AddShape(msoShapeOval, .Left, .Top, .Width, .Height) With BoutonCourant .Fill.ForeColor.SchemeColor = 10 ' rouge .Fill.BackColor.SchemeColor = 11 ' vert .Line.ForeColor.SchemeColor = 22 ' gris .OLEFormat.Object.Caption = "O" '----affecter une macro .OnAction = "Bouton_Click" .Select With Selection .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter End With '(caption) End With '(bouton) .Value = False '---- la cellule reçoit FAUX=bouton Rouge, VRAI=Bouton Vert End With '(cellule) DoEvents Next [a1].Select End Sub