Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to pass ListBox into a Sub?
Hi all,
I am trying to pass a Listbox into a sub, and declared something like this: Sub Handle_ListBox (MyListBox as ListBox) MyListBox.Enabled=False .... End sub When I try to pass a listbox to the sub: Handle_Listbox formHello.listboxVendors I get a "type mismatch" error. The same approach works perfectly for combo box. What's the difference? Where am I wrong? Thanks - RADO |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to pass ListBox into a Sub?
Rado,
The reason is the both Excel and MSForms define an object with the name 'ListBox'. The compiler uses the one defined in Excel, because Excel's type library has a higher precedence that MSForms. The solution is to qualify the object type name with the MSForm library. E.g., Sub Handle_ListBox (MyListBox as MSForms.ListBox) The reason that it works for Comboboxes is that Excel doesn't have an object named " "Combobox". (Comboboxes on Excel sheets, from the Forms tool bar are called DropDowns.) -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "RADO" wrote in message ... Hi all, I am trying to pass a Listbox into a sub, and declared something like this: Sub Handle_ListBox (MyListBox as ListBox) MyListBox.Enabled=False .... End sub When I try to pass a listbox to the sub: Handle_Listbox formHello.listboxVendors I get a "type mismatch" error. The same approach works perfectly for combo box. What's the difference? Where am I wrong? Thanks - RADO |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
How to pass ListBox into a Sub?
Chip,
I am very impressed, to say the least!! Thanks so mach - I had no clue... RADO "Chip Pearson" wrote in message ... Rado, The reason is the both Excel and MSForms define an object with the name 'ListBox'. The compiler uses the one defined in Excel, because Excel's type library has a higher precedence that MSForms. The solution is to qualify the object type name with the MSForm library. E.g., Sub Handle_ListBox (MyListBox as MSForms.ListBox) The reason that it works for Comboboxes is that Excel doesn't have an object named " "Combobox". (Comboboxes on Excel sheets, from the Forms tool bar are called DropDowns.) -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com "RADO" wrote in message ... Hi all, I am trying to pass a Listbox into a sub, and declared something like this: Sub Handle_ListBox (MyListBox as ListBox) MyListBox.Enabled=False .... End sub When I try to pass a listbox to the sub: Handle_Listbox formHello.listboxVendors I get a "type mismatch" error. The same approach works perfectly for combo box. What's the difference? Where am I wrong? Thanks - RADO |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Listbox 2 takes the value of Listbox 1 | Excel Discussion (Misc queries) | |||
listbox B conditional of input in Listbox A | Excel Discussion (Misc queries) | |||
listbox.value not equal to listbox.list(listbox.listindex,0) | Excel Programming | |||
Is refreshing listbox rowsource in listbox click event possible? | Excel Programming | |||
Sorting ListBox results or transposing ListBox values to other cells for sorting | Excel Programming |