PDA

View Full Version : Getting to know what element of ComboBox has been selected



chamster
09-10-2007, 06:08 AM
This might sound a little bit stupid but i have no idea how to change a name of a combo box that i've placed ona sheet. In fact, i didn't even know what the name was until i recorded a macro doing things with the combo box and then check that out.

How does one check a name of such component?

rory
09-10-2007, 06:10 AM
The name should appear in the Name box on the left of the formula bar. You can change it there too.

chamster
09-10-2007, 06:24 AM
This is a two-part question.

a. How do i get to learn what element of a combo box has just been selected? I can intercept the act of selecting but i have no idea how to learn what element that has been selected.

b. The above is a general problem i have. Where to i find e.g. all kinds of xlSomething when looking for the best line width? Or, e.g. where do i find all methods applicable to a button or combo box?

rory
09-10-2007, 06:35 AM
a. What kind of combobox and where is it?
b. In the VB Editor, use the Object Browser (f2).

chamster
09-10-2007, 06:54 AM
a. The usual combo box i pulled down from a toolbar right into a sheet.
b. Thanks.

rory
09-10-2007, 06:58 AM
Which toolbar - Forms or the Control Toolbox? You can link both to a cell but they return different things: the Forms toolbar control returns an index value (i.e. if you select the third item in the list, it returns 3, not the item itself); the Control Toolbox one will return the actual item. The coding is different too if you want to use VBA.

chamster
09-10-2007, 06:59 AM
By the way, when i run this code
MsgBox ActiveSheet.Shapes("RouteSelector").Value
i get errors about .Value not being a property. Perhaps it's not a ComboBox we're looking at here... It looks like one, though...

chamster
09-10-2007, 07:00 AM
How do i check that? I can see the name but it's in swedish and the translation will be "combo box"... What if we assume each of the alternatives you mentioned and come up with a suggestion for each?

lucas
09-10-2007, 07:05 AM
Hi chamster,
Please keep all of your general questions about comboboxes etc. in one thread. These are very basic questions and you should be doing some reading on your own to get these answers and spreading them over several threads will cause folks to ignore your questions.

Rapid fire questions and then another question before you have even figured out the first one will frustrate anyone trying to help you.

This begins to sound like homework....

rory
09-10-2007, 07:05 AM
If you pulled it down from a toolbar, you must know which one?! If you right-click it, what, if any, options do you get?

To get the value from a Control toolbox combo:
?activesheet.shapes("RouteSelector").oleformat.object.object.value
?activesheet.oleobjects("RouteSelector").object.value

lucas
09-10-2007, 07:11 AM
Threads merged

chamster
09-11-2007, 04:35 AM
Please keep all of your general questions about comboboxes etc. in one thread.

I thought i did. I'll try harder next time.


This begins to sound like homework...

It's been a while since i had one of those. I'd be grateful if it was so. Unfortunately, once one turnes 25-30 or so, there's no homeworks - only a cruel boss. :whip

chamster
09-11-2007, 04:54 AM
If you pulled it down from a toolbar, you must know which one?! If you right-click it, what, if any, options do you get?

To get the value from a Control toolbox combo:
?activesheet.shapes("RouteSelector").oleformat.object.object.value
?activesheet.oleobjects("RouteSelector").object.value

Now i got it. Sorry for yesterday - i must have temporary brain damage or something... I pulled the one from forms-toolbar, to answer your question.

Now, that i see what you ment, i get the impression that form-way is easier but control-way more programatical. Do i get it right?

rory
09-11-2007, 05:08 AM
Forms controls are simpler and more stable generally; controls from the Control Toolbox expose more properties, methods and events but unless you need the added functionality, I would stick with the Forms controls. Be aware though that the value returned will be the index value, not the text itself - you can return it with:
activesheet.dropdowns(1).Value