The command bar has three menu items. Each of the menu items are assigned to a macro.
Here is how to go about creating a custom command bar:
Step 1: Create a new Excel file and use the code below to create your own command bar
Step 2: Save the file as an AddIn, for example "Utility.xla".
Step 3: Go to Tools -> Add-ins and browse the addin file you created as shown. Each time Excel is opened, this add-in is called and the Command Bar is ready to use.
'========================================================================= ' Creating Utility Command Bar with Button Menu Items with Icons
' Copyright vbacentral.blogspot.com '========================================================================= Option Explicit
Sub Create_Utility_Menu() Dim MyBar As CommandBar Dim MyPopup As CommandBarPopup Dim MyButton As CommandBarButton ' Delete Menu, if it was already created On Error Resume Next CommandBars("Utility Menu").Delete On Error GoTo 0 ' Create a Command Bar object on the bottom of the Excel window Set MyBar = CommandBars.Add(Name:"Utility Menu", _ Position:=msoBarBottom, Temporary:=True) With MyBar '.Width = 200 .Visible = True Set MyButton = MyBar.Controls.Add(Type:=msoControlButton) With MyButton .Caption = "Move Sheets Around" .Style = msoButtonIconAndCaption 'Other Menu item types include: 'msoButtonAutomatic, msoButtonIcon, msoButtonCaption, or msoButtonIconandCaption .BeginGroup = True 'Assign a macro (in this case macro name is MoveSheets) .OnAction = "MoveSheets" 'Assign a picture icon using predefined Office icons .FaceId = 1771 End With Set MyButton = MyBar.Controls.Add(Type:=msoControlButton) With MyButton .Caption = "Hide/Unhide Sheets" .Style = msoButtonIconAndCaption .BeginGroup = True 'Assign a macro (in this case macro name is HideUnhideSelectedSheets) .OnAction = "HideUnhideSelectedSheets" 'Assign a picture icon using predefined Office icons .FaceId = 488 End With Set MyButton = MyBar.Controls.Add(Type:=msoControlButton) With MyButton .Caption = "Go to Sheet" .Style = msoButtonIconAndCaption .BeginGroup = True 'Assign a macro (in this case macro name is GoToSheet) .OnAction = "GoToSheet" 'Assign a picture icon using predefined Office icons .FaceId = 917 End With End With End Sub
This is very sophisticated use of Microsoft Powerpoint. Very impressive.
ReplyDeleteI haven't imagined that even a commandbar can be created in VBA. I used to use CommandBar control.
ReplyDelete