Comment créer une barre d'outils dans un document XLA?
-
06-07-2019 - |
Question
Comment créer une barre d'outils pour Excel à l'aide d'un document XLA?
La solution
Pour créer une barre d'outils, dans l'événement onload, vous allez faire quelque chose du genre:
Dim myBar As CommandBar, myButt As CommandBarControl
'Delete the toolbar if it already exists'
On Error Resume Next
CommandBars("My Toolbar").Delete
On Error Goto 0
Set myBar = CommandBars.Add(Name:="My Toolbar", _
Position:=msoBarFloating, Temporary:=True)
myBar.Visible = True
' Create a button with text on the bar and set some properties.'
Set myButt = ComBar.Controls.Add(Type:=msoControlButton)
With myButt
.Caption = "Macro1"
.Style = msoButtonCaption
.TooltipText = "Run Macro1"
.OnAction = "Macro1"
End With
' Create a button with an image on the bar and set some properties.'
Set myButt = ComBar.Controls.Add(Type:=msoControlButton)
With myButt
'the faceId line will let you choose an icon'
' If you choose to use the faceId then the caption is not displayed'
.FaceId = 1000
.Caption = "Icon Button"
.TooltipText = "Run Macro2"
.OnAction = "Macro2"
End With
La chose la plus polie à faire est de supprimer également la barre d’outils à la sortie.
Autres conseils
Je ne sais pas si c'est ce que vous cherchez, mais j'ai pensé que cela pourrait vous aider:
Excel - Barre d’outils pour les macros
Puisque vous ne spécifiez pas de version d'Excel, je ne suis pas sûr que cela fonctionne pour vous ou non, mais cela vous fournira peut-être un bon point de départ.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow