Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default 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   Report Post  
Posted to microsoft.public.excel.programming
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox 2 takes the value of Listbox 1 Illya Teideman Excel Discussion (Misc queries) 3 April 10th 07 03:20 PM
listbox B conditional of input in Listbox A Kim K Excel Discussion (Misc queries) 1 October 31st 06 08:27 PM
listbox.value not equal to listbox.list(listbox.listindex,0) ARB Excel Programming 0 October 22nd 03 12:46 AM
Is refreshing listbox rowsource in listbox click event possible? Jeremy Gollehon[_2_] Excel Programming 4 September 25th 03 06:45 PM
Sorting ListBox results or transposing ListBox values to other cells for sorting Rob[_8_] Excel Programming 1 July 9th 03 04:35 AM


All times are GMT +1. The time now is 03:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"