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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
Private Sub CreationBarre()
Dim Barre As CommandBar
Dim Btn As CommandBarButton
Dim I As Integer
'supprime les contrôles de l'onglet "Complément"
'(Excel 2007, pas testé sur ultérieur)
For Each Btn In CommandBars(1).Controls
Debug.Print Btn.Caption
Btn.Delete
Next Btn
'ceci crée un onglet "Complément"
Set Barre = CommandBars(1)
'ajoute un 1er bouton avec une icône
'pour l'exemple "Nouveau fichier"
Set Btn = Barre.Controls.Add(msoControlButton, 2520)
With Btn
.Caption = "Macro1"
.OnAction = "MaMacro1"
.Visible = True
End With
'ajoute un 2ème bouton avec une icône
'pour l'exemple "Enregistrer"
Set Btn = Barre.Controls.Add(msoControlButton, 3)
With Btn
.Caption = "Macro2"
.OnAction = "MaMacro2"
.Visible = True
End With
Barre.Visible = True
End Sub
Sub MaMacro1()
MsgBox "Macro 1"
End Sub
Sub MaMacro2()
MsgBox "Macro 2"
End Sub |
Partager