Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Création BO à ouverture d'un fichier

1 réponse
Avatar
calendrier
Bonjour,

bonne année à tous ceux qui sont là et pas là

je cherche un petit truc simple
à partir de VBA, comment à l'ouverture d'un fichier excel créer une barre
d'outils
Cette barre d'outils doit disparaitre à la fermeture du fichier excel

mon fichier s'apelle "COMPTA"

merci à l'avance pour votre aide

jean marie

1 réponse

Avatar
ChrisV
Bonjour calendrier,

Par exemple...

Dans la feuille de code de ThisWorkbook:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
DeleteBO
End Sub

Private Sub Workbook_Open()
CreateBO
End Sub

Private Sub Workbook_WindowActivate(ByVal Wn As Window)
On Error Resume Next
Application.CommandBars(nomBO).Visible = True
End Sub

Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
On Error Resume Next
Application.CommandBars(nomBO).Visible = False
End Sub

dans un module:

Public Const nomBO = "Ma barre d'outils personnalisée"

Sub CreateBO()
Dim bo As CommandBar
On Error Resume Next
DeleteBO
Set bo = Application.CommandBars.Add(nomBO)
With bo.Controls.Add(msoControlButton)
.Caption = "Titre 1"
.FaceId = 487
.OnAction = "Macro1"
End With
With bo.Controls.Add(msoControlButton)
.Caption = "Titre 2"
.FaceId = 210
.OnAction = "Macro2"
End With
With bo.Controls.Add(msoControlButton)
.Caption = "Titre 3"
.FaceId = 211
.OnAction = "Macro3"
End With
With bo.Controls.Add(msoControlButton)
.Caption = "Titre 4"
.FaceId = 266
.OnAction = "Macro4"
.BeginGroup = True
End With
With bo.Controls.Add(msoControlButton)
.Caption = "Titre5"
.FaceId = 2151
.OnAction = "Macro5"
End With
bo.Visible = True
End Sub

Sub DeleteBO()
On Error Resume Next
Application.CommandBars(nomBO).Delete
End Sub


ChrisV


"calendrier" a écrit dans le message
de news:
Bonjour,

bonne année à tous ceux qui sont là et pas là

je cherche un petit truc simple
à partir de VBA, comment à l'ouverture d'un fichier excel créer une barre
d'outils
Cette barre d'outils doit disparaitre à la fermeture du fichier excel

mon fichier s'apelle "COMPTA"

merci à l'avance pour votre aide

jean marie