Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to transfer a ListBox to a function

In VBA I'd like to transfer a ListBox to a function.

For example:
Private Sub CommandButton1_Click()
Call GetIndex(ListBox1)
End Sub

Public Sub GetIndex(TempListBox As ListBox)
MsgBox (TempListBox.ListIndex)
End Sub

Why do I get in VBA (e.g. Excel) at the statement
Call GetIndex(ListBox1)
the Run-time error '13' (Type mismatch)? In real VB it works.

PS: If I use
Public Sub GetIndex(TempListBox As Variant)
it works. But I don't understand why.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default How to transfer a ListBox to a function

Give this a whirl...

Private Sub CommandButton1_Click()
Call GetIndex(ListBox1)
End Sub

Public Sub GetIndex(TempListBox As MSForms.ListBox)
MsgBox (TempListBox.ListIndex)
End Sub

In XL there are a couple of different types of listboxes. Unless specified
otherwise VBA assumes you mean the native listbox (the type that comes from
the forms toolbar) not the ActiveX control that you are using in your form
(or at least I think that is the way it works)...
--
HTH...

Jim Thomlinson


"Stefan Mueller" wrote:

In VBA I'd like to transfer a ListBox to a function.

For example:
Private Sub CommandButton1_Click()
Call GetIndex(ListBox1)
End Sub

Public Sub GetIndex(TempListBox As ListBox)
MsgBox (TempListBox.ListIndex)
End Sub

Why do I get in VBA (e.g. Excel) at the statement
Call GetIndex(ListBox1)
the Run-time error '13' (Type mismatch)? In real VB it works.

PS: If I use
Public Sub GetIndex(TempListBox As Variant)
it works. But I don't understand why.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 20
Default How to transfer a ListBox to a function

Great, many thanks.

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
Transfer ListBox items to a range AD108 Excel Programming 2 September 10th 06 01:49 PM
userform listbox cannot get listbox.value to transfer back to main sub [email protected] Excel Programming 1 May 17th 06 09:44 PM
How do I transfer a keyboard function key to a terminal emulator? covington Excel Worksheet Functions 0 September 29th 05 09:25 PM
transfer data in listbox Glen Mettler[_2_] Excel Programming 1 September 24th 04 10:44 AM
Transfer multiple columns items form listbox to range Rolo[_3_] Excel Programming 3 November 15th 03 06:50 PM


All times are GMT +1. The time now is 04:57 PM.

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

About Us

"It's about Microsoft Excel"