Add Combo Box to the command Bar
Sub Show_Combo_CommandBar()
Dim oCB As CommandBar
Dim oCtl As CommandBarComboBox
On Error Resume Next
'Delete Control From CommandBar
CommandBars("Sample Command Bar").Delete
Set oCB = CommandBars.Add
oCB.Name = "Sample Command Bar"
oCB.AdaptiveMenu = True
'Add Control to CommandBar
Set oCtl = oCB.Controls.Add(Type:=msoControlComboBox)
oCtl.Caption = "ComboSamp"
'Link Macro to CommandBar,
oCtl.OnAction = "Change_Header_Background"
'Add list Item to Combo Box Control
oCtl.AddItem "NoColor"
oCtl.AddItem "Blue"
oCtl.AddItem "Yellow"
' Show the Command Bar
oCB.Visible = True
' Place the CommandBar at the bottom of the screen
oCB.Position = msoBarBottom
End Sub
Sub Change_Header_Background()
' Acts based on the value in the Combo Box
Dim oCB As CommandBar
Dim oCtl As CommandBarComboBox
On Error Resume Next
Set oCB = CommandBars("Sample Command Bar")
Set oCtl = oCB.Controls("ComboSamp")
If oCtl.ListIndex <> -1 Then
Select Case oCtl.ListIndex
Case 1
ActiveSheet.Rows(1).Interior.ColorIndex = 0
Case 2
ActiveSheet.Rows(1).Interior.ColorIndex = 5
Case 3
ActiveSheet.Rows(1).Interior.ColorIndex = 36
Case Else
' Do nothing
End Select
End If
' Show the Command Bar
oCB.Visible = True
' Place the CommandBar at the bottom of the screen
oCB.Position = msoBarBottom
End Sub
Showing posts with label VBA Customize Command Bar. Show all posts
Showing posts with label VBA Customize Command Bar. Show all posts
Monday, May 07, 2007
Subscribe to:
Posts (Atom)
Download Windows Live Toolbar and personalize your Web experience! Add custom buttons to get the information you care about most.