Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
change combobox values one by one based on selection in multiselect listbox | Excel Programming | |||
userform multiselect listbox problem | Excel Programming | |||
Last Selection from MultiSelect Listbox | Excel Programming | |||
Multiselect ListBox - Active/Inactive Items | Excel Programming | |||
Multiselect listbox selection question | Excel Programming |