Page 403 - Microsoft Office Excel 2003 Programming Inside Out
P. 403

Part 5:  Manipulating Excel Objects
                                                        Command Bars

                    Creating Toolbars
                             A toolbar is a collection of buttons arranged horizontally. You can mix and match various
                             types of buttons together in a single toolbar. (See Figure 17-4.)




























                             Figure 17-4.  You can combine multiple types of buttons into a single command bar to
                             create a toolbar.
                             The following routine was used to create the toolbar shown in Figure 17-4. The code begins
                             by locating the command bar that will hold the controls by using the CommandBars collec­
                             tion and specifying the desired name. Then the routine uses the Add method of the Controls
                             collection to create a new button. The button’s Style property is set the proper style for the
                             button, while the Caption property contains text that might or might not be displayed
                             depending on the type of button.
                                                                                                             Chapter 17
                             Sub  CreateBar()
                             Dim  c  As  CommandBar
                             Dim  cb  As  CommandBarButton
                             Set  c  =  Application.CommandBars("Excel2k3  VBA")

                             Set  cb  =  c.Controls.Add(msoControlButton,  2)
                             cb.Style  =  msoButtonCaption
                             cb.Caption  =  "caption  button  with  a  long  caption"
                             Set  cb  =  c.Controls.Add(msoControlButton,  3)
                             cb.Style  =  msoButtonIcon
                             cb.Caption  =  "icon  button"




                                                                                                       377
   398   399   400   401   402   403   404   405   406   407   408