excel - 如何在 XLA 文档中创建工具栏?

标签 excel commandbar xla vba

如何使用 XLA 文档创建 Excel 工具栏?

最佳答案

要制作工具栏,在 onload 事件中,您将执行以下操作:

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 

礼貌的做法是在退出时删除工具栏。

关于excel - 如何在 XLA 文档中创建工具栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/262267/

相关文章:

vba - 全局变量不能跨类生存?

excel - 使用通配符打开 Excel 工作簿

excel - 尝试使用 pivot 和 ssis 导入 excel 文件

粘贴之前的 Excel VBA 宏 : Check content (of clipboard? )

c# - Internet Explorer 工具栏的上下文菜单

c# - 无法在 Flyout 的 TextBox 控件中输入输入文本

c# - 键盘加速器在 UWP 应用中停止工作

python - 为什么tensorflow.function(不带jit_compile)可以加速Keras模型的前向传递?