Replacing Excel's built-in menu with your own : CommandBar « Application « VBA / Excel / Access / Word






Replacing Excel's built-in menu with your own

 
Sub MakeMenuBar()
    Dim NewMenuBar As commandBar
    Set NewMenuBar = CommandBars.Add(MenuBar:=True)
    With NewMenuBar
        .name = "MyMenuBar"
        .Visible = True
    End With
    
    CommandBars("Worksheet Menu Bar") _
     .Controls(1).Copy Bar:=CommandBars("MyMenuBar")

    Set NewMenu = NewMenuBar.Controls.Add _
      (Type:=msoControlPopup)
    NewMenu.Caption = "&Commands"

    Set NewItem = NewMenu.Controls.Add(Type:=msoControlButton)
    With NewItem
        .Caption = "&Restore Normal Menu"
        .OnAction = "DeleteMenuBar"
    End With
    Set NewItem = NewMenu.Controls.Add(Type:=msoControlButton)
    With NewItem
        .Caption = "&Help"
        .OnAction = "DeleteMenuBar"
    End With
End Sub
Sub DeleteMenuBar()
    On Error Resume Next
    CommandBars("MyMenuBar").Delete
    On Error GoTo 0
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 ControlButton to CommandBar
7.Add PopupControl to CommandBar
8.Set Control style, Action, group, faceid and caption
9.Show All Toolbar Controls
10.Show CommandBar Names
11.Create Shortcut
12.show/hide check symbol
13.Save list of all predefined commands and their ID numbers in a file
14.Shows or hides a command bar.
15.Inspecting a CommandBar
16.Display Control Detail
17.Translates a MsoControlType enumeration into a text description of the control type.
18.Finding Visible Controls with FindControls
19.Add a new commandbar
20.display shortcut menu with the ShowPopup method
21.Custom Toolbars
22.Removes a toolbar specified by the name passed in
23.Creating a command bar: Set some properties when you create a new toolbar
24.Referring to command bars
25.Counting custom toolbars
26.The Protection property of a CommandBar object provides you with many options for protecting a CommandBar.
27.The Protection constants are additive: apply different types of protection with a single command
28.how your VBA code can change the position of a toolbar.
29.This toolbar exists only when the cell pointer falls within a given range
30.Removing all toolbars and then restoring them
31.Restore tool bar
32.displays the Caption property for the first Control object contained in the Standard toolbar, whose index is 3.
33.Rather than use an index number to refer to a control, you can use its Caption property setting
34.Listing the controls on a command bar
35.Listing all controls on all toolbars
36.Adding a control to a command bar
37.To delete a control from a CommandBar object, use the Delete method of the Controls collection
38.deletes a control that has a caption of SortButton.
39.sets the FaceId property of the first button on the MyToolbar toolbar image to 45, which is the code number for a mailbox icon.
40.Adjusting a control's Visible property
41.Changing a control's caption dynamically: Showing the user the current cell's number format
42.simply copies the NumberFormat property of the ActiveCell to the Caption property of the button control.
43.Attaching a drop-down list to a command bar
44.CommandBars collection
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