Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Problem with multiselect listbox items selection

Hi,
I try to use a multiselection listbox, but receive the error message
"Could not get the Selection property. Invalid argument". Any
suggestion why?

Thank you in advance

Frank
_____________________

Dim x As Integer

Private Sub CommandButton1_Click()
ListBox2.Clear
For x = 0 To 9
If ListBox1.Selected(x) = True Then ListBox2.AddItem
ListBox1.List(x)
Next x
End Sub

Private Sub UserForm_Initialize()
Dim myarray()
Dim fs As Object
Dim tekst As String
With UserForm1
.ListBox1.MultiSelect = fmMultiSelectExtended
.CommandButton1.Caption = "Show selections"
.CommandButton1.AutoSize = True
.ListBox2.Clear
Set fs = Application.FileSearch
With fs
.LookIn = "c:\My files\"
.SearchSubFolders = True
.Filename = "*.xls"
If .Execute 0 Then
ReDim myarray(fs.FoundFiles.Count)
For x = 1 To .FoundFiles.Count
myarray(x) = .FoundFiles(x)
Next x
Else
MsgBox "No files found!", vbInformation, "Empty folder"
End If
For x = 1 To fs.FoundFiles.Count
pos1 = InStrRev(myarray(x), "\", , vbTextCompare)
tekst = Mid(myarray(x), 1, pos1 - 1)
UserForm1.ListBox1.AddItem tekst
Next x
End With
End With
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Problem with multiselect listbox items selection

Are you sure that you have (at least) 10 elements in the List? A better way
would be to change your code to

For x = 0 To Me.ListBox1.ListCount -1
If Me.ListBox1.Selected(x) = True Then ......

With this code, you don't have to worry about the number of elements in the
list. It is determined at run time by ListCount -1.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)

wrote in message
oups.com...
Hi,
I try to use a multiselection listbox, but receive the error message
"Could not get the Selection property. Invalid argument". Any
suggestion why?

Thank you in advance

Frank
_____________________

Dim x As Integer

Private Sub CommandButton1_Click()
ListBox2.Clear
For x = 0 To 9
If ListBox1.Selected(x) = True Then ListBox2.AddItem
ListBox1.List(x)
Next x
End Sub

Private Sub UserForm_Initialize()
Dim myarray()
Dim fs As Object
Dim tekst As String
With UserForm1
.ListBox1.MultiSelect = fmMultiSelectExtended
.CommandButton1.Caption = "Show selections"
.CommandButton1.AutoSize = True
.ListBox2.Clear
Set fs = Application.FileSearch
With fs
.LookIn = "c:\My files\"
.SearchSubFolders = True
.Filename = "*.xls"
If .Execute 0 Then
ReDim myarray(fs.FoundFiles.Count)
For x = 1 To .FoundFiles.Count
myarray(x) = .FoundFiles(x)
Next x
Else
MsgBox "No files found!", vbInformation, "Empty folder"
End If
For x = 1 To fs.FoundFiles.Count
pos1 = InStrRev(myarray(x), "\", , vbTextCompare)
tekst = Mid(myarray(x), 1, pos1 - 1)
UserForm1.ListBox1.AddItem tekst
Next x
End With
End With
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Problem with multiselect listbox items selection

On 6 Okt, 22:10, "Chip Pearson" wrote:
Are you sure that you have (at least) 10 elements in the List? A better way
would be to change your code to

For x = 0 To Me.ListBox1.ListCount -1
If Me.ListBox1.Selected(x) = True Then ......

With this code, you don't have to worry about the number of elements in the
list. It is determined at run time by ListCount -1.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consultingwww.cpearson.com
(email on the web site)

wrote in message

oups.com...



Hi,
I try to use a multiselection listbox, but receive the error message
"Could not get the Selection property. Invalid argument". Any
suggestion why?


Thank you in advance


Frank
_____________________


Dim x As Integer


Private Sub CommandButton1_Click()
ListBox2.Clear
For x = 0 To 9
If ListBox1.Selected(x) = True Then ListBox2.AddItem
ListBox1.List(x)
Next x
End Sub


Private Sub UserForm_Initialize()
Dim myarray()
Dim fs As Object
Dim tekst As String
With UserForm1
.ListBox1.MultiSelect = fmMultiSelectExtended
.CommandButton1.Caption = "Show selections"
.CommandButton1.AutoSize = True
.ListBox2.Clear
Set fs = Application.FileSearch
With fs
.LookIn = "c:\My files\"
.SearchSubFolders = True
.Filename = "*.xls"
If .Execute 0 Then
ReDim myarray(fs.FoundFiles.Count)
For x = 1 To .FoundFiles.Count
myarray(x) = .FoundFiles(x)
Next x
Else
MsgBox "No files found!", vbInformation, "Empty folder"
End If
For x = 1 To fs.FoundFiles.Count
pos1 = InStrRev(myarray(x), "\", , vbTextCompare)
tekst = Mid(myarray(x), 1, pos1 - 1)
UserForm1.ListBox1.AddItem tekst
Next x
End With
End With
End Sub- Skjul sitert tekst -


- Vis sitert tekst -


Thank you. I just forgot to modify the If-test in the example I found
in vba help.

Frank

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
change combobox values one by one based on selection in multiselect listbox Abdul[_2_] Excel Programming 0 November 7th 06 11:55 AM
userform multiselect listbox problem apndas[_7_] Excel Programming 4 July 25th 06 04:12 AM
Last Selection from MultiSelect Listbox Brian Excel Programming 4 December 3rd 05 07:13 AM
Multiselect ListBox - Active/Inactive Items LCK[_2_] Excel Programming 2 November 3rd 05 12:39 AM
Multiselect listbox selection question Paul Mueller Excel Programming 3 June 16th 04 09:25 PM


All times are GMT +1. The time now is 07:53 PM.

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"