Sub CommandBarreCréerAvecBoutonEtMenu()
Dim LaBarre As CommandBar
Dim Moncontrol As Object
Dim lignebar(1 To 3) As CommandBar
deleteBars
'on créée 3 barres
Set lignebar(1) = Application.CommandBars.Add
Set lignebar(2) = Application.CommandBars.Add
Set lignebar(3) = Application.CommandBars.Add
With lignebar(1)
.Name = "Barredonnée1"
Set Moncontrol = .Controls.Add(msoControlButton, , , , True)
With Moncontrol
.Style = msoButtonIconAndCaption
.Caption = "Ajouter une donnée"
.OnAction = "Macro1"
.FaceId = 989
End With
Set Moncontrol = .Controls.Add(msoControlPopup, , , , True)
With Moncontrol
.Caption = "menu Format de donnée"
For i = 1 To 5
Set itemmenu = .Controls.Add(msoControlButton, , , , True)
With itemmenu
.Style = msoButtonIconAndCaption
.Caption = "format" & i
.OnAction = "Macro1"
.FaceId = 989
End With
Next
End With
.Visible = True
End With
With lignebar(2)
.Name = "Barredonnée2"
Set Moncontrol = .Controls.Add(msoControlButton, , , , True)
With Moncontrol
.Style = msoButtonIconAndCaption
.Caption = "Modifier une donnée"
.OnAction = "Macro2"
.FaceId = 989
End With
.Visible = True
End With
With lignebar(3)
.Name = "Barredonnée3"
Set Moncontrol = .Controls.Add(msoControlButton, , , , True)
With Moncontrol
.Style = msoButtonIconAndCaption
.Caption = "Supprimer une donnée"
.OnAction = "Macro2"
.FaceId = 989
End With
.Visible = True
End With
End Sub
Sub deleteBars()
Dim i&
For i = 1 To 3
On Error Resume Next
CommandBars("Barredonnée" & i).Delete
Next
End Sub