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
| Private Sub CreationBarre()
Dim CmdBar As CommandBar
Dim Bouton As CommandBarButton
Dim xlwkb As Workbook
Dim xlwks As Worksheet
Dim i As Integer
Application.CommandBars("Barre").Delete 'effacer la barre d'outils précedente
'Création de la barre d'outils nommée 'Barre'
Set CmdBar = Application.CommandBars _
.Add(Name:="Barre", Position:=msoBarTop, Temporary:=True)
Set xlwkb = Workbooks("macrobarre")
Set xlwks = xlwkb.Sheets(1)
xlwks.Activate
For i = 1 To xlwks.Shapes.Count
xlwks.Shapes(i).Copy
'Ajout de boutons dans la barre d'outils
Set Bouton = CmdBar.Controls.Add(Type:=msoControlButton)
With Bouton
.Caption = xlwks.Cells(3, i)
.PasteFace 'colle l'image qui va s'afficher sur le bouton
'Définit quelle macro est associée au bouton.
.OnAction = xlwks.Cells(4, i)
End With
Next i
'xlwkb.Close
CmdBar.Visible = True
End Sub |
Partager