View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default 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