ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Listbox on custom toolbar? (https://www.excelbanter.com/excel-programming/284636-listbox-custom-toolbar.html)

Larry Adams

Listbox on custom toolbar?
 
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!!


Bill Manville

Listbox on custom toolbar?
 
Larry Adams wrote:
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


Larry Adams

Combobox on custom toolbar?
 
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!

Bill Manville wrote:

Larry Adams wrote:
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 Manville

Combobox on custom toolbar?
 
Larry Adams wrote:
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


Larry Adams

Combobox on custom toolbar?
 
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.

Bill Manville wrote:

Larry Adams wrote:
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



Bill Manville

Combobox on custom toolbar?
 
Larry Adams wrote:
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



All times are GMT +1. The time now is 12:27 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com