代码之家  ›  专栏  ›  技术社区  ›  Jason

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

  •  2
  • Jason  · 技术社区  · 16 年前

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

    2 回复  |  直到 11 年前
        1
  •  3
  •   BradC    16 年前

    要创建工具栏,在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 
    

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

        2
  •  1
  •   Onorio Catenacci    16 年前

    不确定这是否是你要找的,但我认为这可能有助于你:

    Excel -- Macro Toolbar

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

    推荐文章