Como faço para criar uma barra de ferramentas em um documento XLA?
-
06-07-2019 - |
Pergunta
Como faço para criar uma barra de ferramentas para o Excel usando um documento XLA?
Solução
Para fazer uma barra de ferramentas, no evento onload, você está indo para fazer algo como:
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
A coisa educada a fazer é eliminar a barra de ferramentas na saída, também.
Outras dicas
Não sei se isso é o que você está procurando, mas eu pensei que isso poderia ajudá-lo:
Uma vez que você não especificar uma versão do Excel não tenho certeza se isso vai funcionar para você ou não, mas talvez ele irá fornecer-lhe um bom ponto de partida.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow