Listbox on custom toolbar?

  • Thread starter Thread starter Larry Adams
  • Start date Start date
L

Larry Adams

Excel allows one to drag a listbox, combo box, etc. to a custom toolbar,
and will label it to match -- but I cannot find any references as to how
to populate. I'm thinking it needs to be done through code as I cannot
bring up the properties window to assigned a source range or linked cell
as one would do if placing on a form. Any thoughts??? Thanks!!
 
Larry said:
Excel allows one to drag a listbox, combo box, etc. to a custom toolbar,
and will label it to match -- but I cannot find any references as to how
to populate.

I am not aware that you can put a listbox on a toolbar, but certainly you
can create a commbobox or dropdown by using code

Sub test()
With Application.CommandBars.Add("MyBar", temporary:=True)
.Visible = True
With .Controls.Add(msoControlDropdown)
.Caption = "MyBox"
.AddItem "A"
.AddItem "B"
.AddItem "C"
End With
End With
End Sub

Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup
 
Bill, I very much appreciate the example, but now I need to understand the
coding conventions to (a) identify and (b) work with an existing combobox
control on an existing toolbar. Any suggestions? Thanks!
 
Larry said:
I need to understand the
coding conventions to (a) identify and (b) work with an existing combobox
control on an existing toolbar.


With Application.CommandBars("MyToolbar")
With .Controls("MyComboBox") ' the name is the caption that pops up
MsgBox .Value & " is selected" & vbCrLf & "It is entry " & .ListIndex+1
End With
End With

If that doesn't cover what you wanted, please give more details.

Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup
 
Okay, this gave me enough clues and I have some test code running okay. By
"work with an existing combo box control", I was mostly looking for a good
summary of what properties and methods apply specifically to toolbars and
toolbar controls. The help system has this information, more or less, but I
have been hoping to find a comprehensive example showing what all one can do in
working with toolbar controls. But I have a working start -- which is much
better than before. Thanks much. Larry.
 
Larry said:
By
"work with an existing combo box control", I was mostly looking for a good
summary of what properties and methods apply specifically to toolbars and
toolbar controls.

Look in the object browser for CommandBarComboBox

Bill Manville
MVP - Microsoft Excel, Oxford, England
No email replies please - reply in newsgroup
 
Back
Top