OVH Cloud OVH Cloud

BO personnalisée

2 réponses
Avatar
Tial
Bonjour =E0 toutes et tous.

J'ai une BO personnalise=E9. Dans cette derni=E8re, comment=20
puis je ajouter
un bouton qui actionnerait ma macro "toto".

Par avance merci


Sub CreateBO()
'Cr=E9ation de la barre d'outils "Forme Libre"
With Application
.ScreenUpdating =3D False
.CommandBars.Add(Name:=3D"Forme libre").Visible =3D True
.CommandBars("Forme libre").Controls.Add=20
Type:=3DmsoControlButton, Id:=3D21, Before:=3D1
.CommandBars("Forme libre").Controls.Add=20
Type:=3DmsoControlButton, Id:=3D22, Before:=3D2
.CommandBars("Forme libre").Controls.Add=20
Type:=3DmsoControlButton, Id:=3D206, Before:=3D1
.CommandBars("Forme libre").Controls.Add=20
Type:=3DmsoControlButton, Id:=3D200, Before:=3D1
End With
ActiveSheet.Shapes.AddShape(msoShapeRectangle, 1, 1, 1,=20
1). _
Select
With Selection.ShapeRange
.Fill.Visible =3D msoFalse
.Line.Weight =3D 0.5
.Line.ForeColor.SchemeColor =3D 48
.SetShapesDefaultProperties
End With
Selection.Delete
End Sub

2 réponses

Avatar
Frédéric Sigonneau
Bonjour,

Une solution possible :

'====================== Sub CreateBO()
'Création de la barre d'outils "Forme Libre"
With Application
.ScreenUpdating = False
.CommandBars.Add(Name:="Forme libre").Visible = True
With .CommandBars("Forme libre")
.Controls.Add Type:=msoControlButton, ID:!, Before:=1
.Controls.Add Type:=msoControlButton, ID:", Before:=2
.Controls.Add Type:=msoControlButton, ID: 6, Before:=1
.Controls.Add Type:=msoControlButton, ID: 0, Before:=1
With .Controls.Add(msoControlButton)
.OnAction = "toto"
.FaceId = 59
End With
End With
End With
End Sub

Sub toto()
MsgBox "coucou"
End Sub
'======================
FS
--
Frédéric Sigonneau [MVP Excel - né un sans-culottide]
Gestions de temps, VBA pour Excel :
http://perso.wanadoo.fr/frederic.sigonneau
Si votre question sur Excel est urgente, évitez ma bal !


Bonjour à toutes et tous.

J'ai une BO personnaliseé. Dans cette dernière, comment
puis je ajouter
un bouton qui actionnerait ma macro "toto".

Par avance merci

Sub CreateBO()
'Création de la barre d'outils "Forme Libre"
With Application
.ScreenUpdating = False
.CommandBars.Add(Name:="Forme libre").Visible = True
.CommandBars("Forme libre").Controls.Add
Type:=msoControlButton, Id:!, Before:=1
.CommandBars("Forme libre").Controls.Add
Type:=msoControlButton, Id:", Before:=2
.CommandBars("Forme libre").Controls.Add
Type:=msoControlButton, Id: 6, Before:=1
.CommandBars("Forme libre").Controls.Add
Type:=msoControlButton, Id: 0, Before:=1
End With
ActiveSheet.Shapes.AddShape(msoShapeRectangle, 1, 1, 1,
1). _
Select
With Selection.ShapeRange
.Fill.Visible = msoFalse
.Line.Weight = 0.5
.Line.ForeColor.SchemeColor = 48
.SetShapesDefaultProperties
End With
Selection.Delete
End Sub


Avatar
Tial
Grand merci à toi Frédéric