Add ControlButton to CommandBar : CommandBar « Application « VBA / Excel / Access / Word

Home
VBA / Excel / Access / Word
1.Access
2.Application
3.Data Type
4.Data Type Functions
5.Date Functions
6.Excel
7.File Path
8.Forms
9.Language Basics
10.Math Functions
11.Outlook
12.PowerPoint
13.String Functions
14.Windows API
15.Word
16.XML
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
VBA / Excel / Access / Word » Application » CommandBar 
Add ControlButton to CommandBar
 
Sub AddNewMB()
   Dim myCommandBar As CommandBar, myCommandBarCtl As CommandBarControl
   Dim myCommandBarSubCtl As CommandBarControl
   On Error GoTo AddNewMB_Err

   Set myCommandBar = CommandBars.Add(Name:="Sample Menu Bar", Position:= _
      msoBarTop, MenuBar:=True, Temporary:=False)
   myCommandBar.Visible = True
   myCommandBar.Protection = msoBarNoMove

   Set myCommandBarCtl = myCommandBar.Controls.Add(Type:=msoControlPopup)
   myCommandBarCtl.Caption = "Displa&y"

   Set myCommandBarSubCtl = myCommandBarCtl.Controls.Add(Type:=msoControlButton)
   With myCommandBarSubCtl
      .Style = msoButtonIconAndCaption
      .Caption = "E&nable ClickMe"
      .FaceId = 59
      .OnAction = "=MsgBox(""You clicked Enable ClickMe"")"
      .Parameter = 1
      .BeginGroup = True
   End With
   Set myCommandBarSubCtl = myCommandBarCtl.Controls.Add(Type:=msoControlButton)
   With myCommandBarSubCtl
      .Style = msoButtonIconAndCaption
      .Caption = "Di&sable ClickMe"
      .FaceId = 276
      .OnAction = "=MsgBox(""You Disable ClickMe"")"
      .Parameter = 2
      .BeginGroup = True
   End With

   Set myCommandBarCtl = myCommandBar.Controls.Add(Type:=msoControlButton)
   With myCommandBarCtl
      .BeginGroup = True
      .Caption = "&ClickMe"
      .Style = msoButtonCaption
      .OnAction = "=MsgBox(""You clicked ClickMe"")"
   End With

   Set myCommandBarCtl = myCommandBar.Controls.Add(Type:=msoControlButton)
   With myCommandBarCtl
      .BeginGroup = True
      .Caption = "&Set Visibility Off"
      .Style = msoButtonCaption
      .OnAction = "=MsgBox(""You set visibility off"")"
   End With
   Exit Sub
AddNewMB_Err:
   msgBox "Error " & Err.number & vbCr & Err.Description
   Exit Sub
End Sub

 
Related examples in the same category
1.CommandBar Object
2.Creating a Toolbar and display MsgBox in its action
3.Creating a Toolbar and assign its action
4.Get the type of CommandBars
5.Creating a Toolbar: AddRemoveButton
6.Add PopupControl to CommandBar
7.Set Control style, Action, group, faceid and caption
8.Show All Toolbar Controls
9.Show CommandBar Names
10.Create Shortcut
11.show/hide check symbol
12.Save list of all predefined commands and their ID numbers in a file
13.Shows or hides a command bar.
14.Inspecting a CommandBar
15.Display Control Detail
16.Translates a MsoControlType enumeration into a text description of the control type.
17.Finding Visible Controls with FindControls
18.Add a new commandbar
19.display shortcut menu with the ShowPopup method
20.Custom Toolbars
21.Removes a toolbar specified by the name passed in
22.Creating a command bar: Set some properties when you create a new toolbar
23.Referring to command bars
24.Counting custom toolbars
25.The Protection property of a CommandBar object provides you with many options for protecting a CommandBar.
26.The Protection constants are additive: apply different types of protection with a single command
27.how your VBA code can change the position of a toolbar.
28.This toolbar exists only when the cell pointer falls within a given range
29.Removing all toolbars and then restoring them
30.Restore tool bar
31.displays the Caption property for the first Control object contained in the Standard toolbar, whose index is 3.
32.Rather than use an index number to refer to a control, you can use its Caption property setting
33.Listing the controls on a command bar
34.Listing all controls on all toolbars
35.Adding a control to a command bar
36.To delete a control from a CommandBar object, use the Delete method of the Controls collection
37.deletes a control that has a caption of SortButton.
38.sets the FaceId property of the first button on the MyToolbar toolbar image to 45, which is the code number for a mailbox icon.
39.Adjusting a control's Visible property
40.Changing a control's caption dynamically: Showing the user the current cell's number format
41.simply copies the NumberFormat property of the ActiveCell to the Caption property of the button control.
42.Attaching a drop-down list to a command bar
43.CommandBars collection
44.Replacing Excel's built-in menu with your own
45.Working with Shortcut Menus
46.Properties of CommandBar controls
47.Reset CommandBar
48.The custom toolbar is removed with this procedure
49.Translates a MsoBarType enumeration into a text description of the bar type.
50.Translates a MsoBarPosition enumeration into a text description of the bar position.
51.Determines if a given command bar name exists
52.Restores the Worksheet Menu Bar to its native state
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.