Posted By

Maikel on 05/27/11


Tagged

excel


Versions (?)

Create a Toolbar in excel


 / Published in: Visual Basic
 

  1. Dim myBar As CommandBar, myButt As CommandBarControl
  2.  
  3. 'Delete the toolbar if it already exists'
  4. On Error Resume Next
  5. CommandBars("My Toolbar").Delete
  6. On Error Goto 0
  7.  
  8. Set myBar = CommandBars.Add(Name:="My Toolbar", Position:=msoBarFloating, Temporary:=True)
  9. myBar.Visible = True
  10.  
  11. ' Create a button with text on the bar and set some properties.'
  12. Set myButt = ComBar.Controls.Add(Type:=msoControlButton)
  13. With myButt
  14. .Caption = "Macro1"
  15. .Style = msoButtonCaption
  16. .TooltipText = "Run Macro1"
  17. .OnAction = "Macro1"
  18. End With
  19.  
  20. ' Create a button with an image on the bar and set some properties.'
  21. Set myButt = ComBar.Controls.Add(Type:=msoControlButton)
  22. With myButt
  23. 'the faceId line will let you choose an icon'
  24. ' If you choose to use the faceId then the caption is not displayed'
  25. .FaceId = 1000
  26. .Caption = "Icon Button"
  27. .TooltipText = "Run Macro2"
  28. .OnAction = "Macro2"
  29. End With

Report this snippet  

You need to login to post a comment.