Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Populate Combo on a toolbar /Word 2000 1

Status
Not open for further replies.

eman6

Programmer
Dec 7, 2004
578
CH
I have created a toolbar with two combo boxes that I need to populate from an excel sheet.
<code>
Dim myList as CommandBarComboBox 'I tried also just ComboBox
Set myList = ActiveDocument.CommandBars("StatusUpdate").Controls("Task")
....
....
</code>
I get a type mismatch error on the set line.

How should I do it please?

______________________________________
Do not expect the truth from a woman.
Pretending is part of her charm.
___________________________________

Eman_2005
Technical Communicator
 
Even worse, it looks like I cannot make a dropdown combo on a toolbar. When I set one, all it does is to insert a drop down combo at the cursor position.

Is it possible to create a Drop down combo on a new toolbar and have it populated via VBA?



______________________________________
Do not expect the truth from a woman.
Pretending is part of her charm.
___________________________________

Eman_2005
Technical Communicator
 
A sample code, assuming that commandbar "Custom" exists:

Code:
Public MyList As CommandBarComboBox

Sub SetCombo()
Set MyList = Application.CommandBars("Custom").Controls.Add(Type:=msoControlComboBox)
With MyList
    .AddItem ActiveSheet.Range("A1")
    .AddItem ActiveSheet.Range("A2")
    .AddItem ActiveSheet.Range("A3")
    .AddItem ActiveSheet.Range("A4")
    .ListIndex = 2
    .OnAction = "ComboAction"
End With
End Sub

Sub ComboAction()
MsgBox MyList.Text
End Sub

combo
 
Thank you for the reply combo.
Is it possible to create the drop down manually (rather than programmatically) and only populate it programmatically?

______________________________________
Do not expect the truth from a woman.
Pretending is part of her charm.
___________________________________

Eman_2005
Technical Communicator
 
I don't think so. When you try to customise the drop-down, most of options are dimmed, you can add manually to the toolbar only button or menuitem.
Maybe it is possible in higher office version, I've tested it in xp.

combo
 
OK, I created it programmatically.
After saving the document, the button will be there for next time the document opens.
Then I run another macro to populate it.
<code>
myList = Application.CommandBars("TaskList").Controls(1)
...etc
</code>
This worked very well :)
Now the next question is: Can I have two columns in this combo?
I have a code-numbered list of tasks, which means that each task in the list has a specific number and a description.
I am using this to let the user fill in a weekly task list report table.
Of course, I could use two combos, one of which will change selection automatically upon the other, but it would look much more professional to have a two-column drop-down list, if at all possible.
You've earned your star anyway ;)


______________________________________
Do not expect the truth from a woman.
Pretending is part of her charm.
___________________________________

Eman_2005
Technical Communicator
 
Sorry to bother again.
Nevermind about the two columns.

How do I create a macro that acts by selecting an item from this combo?

______________________________________
Do not expect the truth from a woman.
Pretending is part of her charm.
___________________________________

Eman_2005
Technical Communicator
 
The macro is assigned using 'OnAction' property. Public reference to control and Text or ListIndex properties can be used to get the selection. In the above code the second macro displays combobox selection.

combo
 
That's what I thought at the beginning, but it gave me an error.
Now I tried it again, and it worked!
Donno what I did wrong before, but now that it's working, why worry ;-)

Many thanks, and another star :)


______________________________________
Perfection is not impossible;
It's very difficult to achieve.
___________________________________

Eman_2005
Technical Communicator
 
Thanks for the star, as for the error, it is possible that you lose reference to the control (after resetting the project for instance), the macro remains assigned to the control but MyList is Nothing. It is safer to refer to the control, in the OnAction procedure, using full path (CommandBars(...).Controls(...)), and using Tag or Parameter to find the control, first setting them in creation code.

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top