' A Placer dans un Module
Public Sub CreationBO()
Dim BaBar As CommandBar, Btn1, Btn2, Btn3
'Supprime la barre si elle existe déjà
On Error Resume Next
Application.CommandBars("MaBarre" ).Delete
On Error GoTo 0
'Set BaBar = Application.CommandBars.Add("MaBarre" )
'BaBar.Left = 50
'BaBar.Top = 120
Set BaBar = Application.CommandBars.Add("MaBarre", Position:=msoBarTop, MenuBar:=False, temporary:=True)
BaBar.Protection = msoBarNoChangeVisible
With BaBar
Set Btn1 = .Controls.Add(msoControlButton)
With Btn1
.Caption = "1er bouton"
.FaceId = 3
.OnAction = "Macro1"
End With
Set Btn2 = .Controls.Add(msoControlButton)
With Btn2
.Caption = "2eme bouton"
.FaceId = 4
.OnAction = "Macro2"
End With
Set Btn3 = .Controls.Add(msoControlButton)
With Btn3
.Caption = "3eme bouton"
.FaceId = 2520
.OnAction = "Macro3"
End With
.Visible = True
End With
End Sub
Private Sub Macro1()
MsgBox "Bouton 1"
End Sub
Private Sub Macro2()
MsgBox "Bouton 2"
End Sub
Private Sub Macro3()
MsgBox "Bouton 3"
End Sub
Public Sub DetruireBO()
On Error Resume Next
Application.CommandBars("MaBarre" ).Delete
End Sub
' A placer dans ThisWorkBook
Private Sub Workbook_BeforeClose(Cancel As Boolean)
DetruireBO
End Sub
Private Sub Workbook_Open()
CreationBO
End Sub
|