[RESOLVED] How to load several comboboxes with the same list
Back again hoping to be rescued :)
I have a Word 2003 userform that contains a series of combo boxes. Six of these comboboxes contain the same (long list) of items. To load these items I am simply using the .additem method.
This works fine and I have simply copied and pasted the same code 6 times. However, I would assume that there is a better way of doing it so that I only have to write the list once, thus shortening the code? I have searched google and vba help but can find nothing.
Any ideas appreciated.
Re: How to load several comboboxes with the same list
You could move the adds into a seperate procedure that take a combox as an argument and then call that proce for each of your comboboxes.
Heres some pseudo-code to get you started.
VB Code:
Sub main()
PopulateCombo Me.ComboBox1
PopulateCombo Me.ComboBox2
'etc
End Sub
Sub PopulateCombo(MyCombo As MSForms.ComboBox)
MyCombo.AddItem "Item1"
MyCombo.AddItem "Item2"
MyCombo.AddItem "Item3"
MyCombo.AddItem "Item4"
MyCombo.AddItem "Item5"
MyCombo.AddItem "Item6"
End Sub
Re: How to load several comboboxes with the same list
Thanks (again) DKenny - worked a treat :)