Thursday, February 17, 2011

How do I create a toolbar in an XLA document?

How do I create a toolbar for Excel using an XLA document?

From stackoverflow
  • Hi Jason,

    Not sure if this is what you're looking for but I thought this might help you out:

    Excel -- Macro Toolbar

    Since you don't specify a version of Excel I'm not sure if this will work for you or not but perhaps it will furnish you with a good starting point.

    Jason : Thanks... Excel 2003, but it should work in 2007 as well.
  • To make a toolbar, in the onload event, you are going to do something like:

    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
    

    The polite thing to do is delete the toolbar on exit, also.

    Onorio Catenacci : @BradC--interesting variable name there. :-)
    BradC : hehe, myBar, myButt, myAss(embly)

0 comments:

Post a Comment