【问题标题】:How do I create a toolbar in an XLA document?如何在 XLA 文档中创建工具栏?
【发布时间】:2010-09-20 16:59:30
【问题描述】:

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

【问题讨论】:

    标签: excel commandbar xla vba


    【解决方案1】:

    要制作工具栏,在 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 
    

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

    【讨论】:

    • @BradC——有趣的变量名。 :-)
    • 呵呵,myBar,myButt,myAss(embly)
    【解决方案2】:

    不确定这是否是您正在寻找的,但我认为这可能会对您有所帮助:

    Excel -- Macro Toolbar

    由于您没有指定 Excel 的版本,我不确定这是否适合您,但也许它会为您提供一个良好的起点。

    【讨论】:

      猜你喜欢
      • 2021-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-21
      • 1970-01-01
      • 2013-02-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多