Option Explicit
Public Const MyCommandBarName As String = "Enregistrements Datas Clients"
Sub DeleteMyCommandBar()
' Efface la barre d'outils MyCommandBarName
On Error Resume Next
Application.CommandBars(MyCommandBarName).Delete
On Error GoTo 0
End Sub
Sub CreateMyCommandBar()
' Création de la barre d'outils personnalisée MyCommandBarName
Dim cb As CommandBar, cbb As CommandBarButton
Application.ScreenUpdating = False
DeleteMyCommandBar ' au cas où celle-ci existe déjà
Set cb = Application.CommandBars.Add(MyCommandBarName, msoBarFloating, False, True)
AddMenuToCommandBar cb, True
End Sub
Private Sub AddMenuToCommandBar(cb As CommandBar, blnBeginGroup As Boolean)
Dim cbb As CommandBarButton
If cb Is Nothing Then Exit Sub
With cb
' Ajout d'un item au menu
Set cbb = cb.Controls.Add(msoControlButton, , , , True)
With cbb
.BeginGroup = True
.Caption = "Lancer Application"
.OnAction = "Lancer_Appli"
.TooltipText = "Lance l'application ..."
.Style = msoButtonIconAndCaption
.FaceId = 25
End With
' Rendre la barre visible
.Visible = True
' Position dans le cas d'une barre flottante
.Left = 300
.Top = 100
End With
' Initialiser les variables
Set cb = Nothing
Set cbb = Nothing
End Sub