Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default MultiSelect ListBox

I have a ListBox populated thru code as:
Sub UserForm_Initialize()
With ListBox1
..AddItem "AttyAdec"
..AddItem "2004"
..AddItem "Dialer"
..AddItem "Blank"
End With
ListBox1.ListIndex = 0
End Sub
With my OK Command as follows:
Private Sub OKButton_Click()


Msg = "You selected" & vbCrLf
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
Msg = Msg & ListBox1.List(i) & vbCrLf
End If
Next i
MsgBox Msg


If ListBox1.ListIndex = 0 Then

ChDir "C:\Documents and Settings\A092048\Desktop"
Workbooks.Open Filename:= _
"C:\Documents and Settings\A092048\Desktop\AttyAdec 090304.xls"

End If

If ListBox1.ListIndex = 1 Then

Workbooks.Open Filename:="C:\Documents and
Settings\A092048\Desktop\2004.xls"
End If

If ListBox1.ListIndex = 2 Then

Workbooks.Open Filename:= _
"C:\Documents and Settings\A092048\Desktop\Dialer.xls"
End If

Unload UserForm1
End Sub

My ListBox is set to 1 = fmMultiSelectMulti but when I select more than one
file, only the last file selected will open. Is there something else I need
to change for it to open more than one file at a time?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 595
Default MultiSelect ListBox

Stephanie

With a MultiSelect listbox, the ListIndex property will return which row has
the focus. It looks like it's just the last row, because that's the row
you're selecting last and the one that has the focus. You need to use the
Selected property like you do in the first loop.

I would suggest that you make your listbox a two-column listbox, with the
second column width = 0 (hidden) and containing the file you want to open.
Then you could

With Me.ListBox1
For i = 0 to .ListCount - 1
If .Selected(i) Then
Workbooks.Open .Column(1,i)
End If
Next i
End With

For more info on multicolumn, multiselect listboxes, see
http://www.dicks-blog.com/archives/2...elect-listbox/
http://www.dicks-blog.com/archives/2...olumn-listbox/
http://www.dicks-blog.com/archives/2...stboxcombobox/

--
Dick Kusleika
MVP - Excel
Excel Blog - Daily Dose of Excel
www.dicks-blog.com

"StephanieH" wrote in message
...
I have a ListBox populated thru code as:
Sub UserForm_Initialize()
With ListBox1
.AddItem "AttyAdec"
.AddItem "2004"
.AddItem "Dialer"
.AddItem "Blank"
End With
ListBox1.ListIndex = 0
End Sub
With my OK Command as follows:
Private Sub OKButton_Click()


Msg = "You selected" & vbCrLf
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
Msg = Msg & ListBox1.List(i) & vbCrLf
End If
Next i
MsgBox Msg


If ListBox1.ListIndex = 0 Then

ChDir "C:\Documents and Settings\A092048\Desktop"
Workbooks.Open Filename:= _
"C:\Documents and Settings\A092048\Desktop\AttyAdec 090304.xls"

End If

If ListBox1.ListIndex = 1 Then

Workbooks.Open Filename:="C:\Documents and
Settings\A092048\Desktop\2004.xls"
End If

If ListBox1.ListIndex = 2 Then

Workbooks.Open Filename:= _
"C:\Documents and Settings\A092048\Desktop\Dialer.xls"
End If

Unload UserForm1
End Sub

My ListBox is set to 1 = fmMultiSelectMulti but when I select more than

one
file, only the last file selected will open. Is there something else I

need
to change for it to open more than one file at a time?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default MultiSelect ListBox

You have a reply in .misc, too.

StephanieH wrote:

I have a ListBox populated thru code as:
Sub UserForm_Initialize()
With ListBox1
.AddItem "AttyAdec"
.AddItem "2004"
.AddItem "Dialer"
.AddItem "Blank"
End With
ListBox1.ListIndex = 0
End Sub
With my OK Command as follows:
Private Sub OKButton_Click()

Msg = "You selected" & vbCrLf
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
Msg = Msg & ListBox1.List(i) & vbCrLf
End If
Next i
MsgBox Msg

If ListBox1.ListIndex = 0 Then

ChDir "C:\Documents and Settings\A092048\Desktop"
Workbooks.Open Filename:= _
"C:\Documents and Settings\A092048\Desktop\AttyAdec 090304.xls"

End If

If ListBox1.ListIndex = 1 Then

Workbooks.Open Filename:="C:\Documents and
Settings\A092048\Desktop\2004.xls"
End If

If ListBox1.ListIndex = 2 Then

Workbooks.Open Filename:= _
"C:\Documents and Settings\A092048\Desktop\Dialer.xls"
End If

Unload UserForm1
End Sub

My ListBox is set to 1 = fmMultiSelectMulti but when I select more than one
file, only the last file selected will open. Is there something else I need
to change for it to open more than one file at a time?


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default MultiSelect ListBox

Sorry about that. I was thinking since my area of concern seemed to shift, I
should re-enter it under the new topic. I should have known you folks were
better than that and it wasn't necessary. Thanks for your help.

"Dave Peterson" wrote:

You have a reply in .misc, too.

StephanieH wrote:

I have a ListBox populated thru code as:
Sub UserForm_Initialize()
With ListBox1
.AddItem "AttyAdec"
.AddItem "2004"
.AddItem "Dialer"
.AddItem "Blank"
End With
ListBox1.ListIndex = 0
End Sub
With my OK Command as follows:
Private Sub OKButton_Click()

Msg = "You selected" & vbCrLf
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
Msg = Msg & ListBox1.List(i) & vbCrLf
End If
Next i
MsgBox Msg

If ListBox1.ListIndex = 0 Then

ChDir "C:\Documents and Settings\A092048\Desktop"
Workbooks.Open Filename:= _
"C:\Documents and Settings\A092048\Desktop\AttyAdec 090304.xls"

End If

If ListBox1.ListIndex = 1 Then

Workbooks.Open Filename:="C:\Documents and
Settings\A092048\Desktop\2004.xls"
End If

If ListBox1.ListIndex = 2 Then

Workbooks.Open Filename:= _
"C:\Documents and Settings\A092048\Desktop\Dialer.xls"
End If

Unload UserForm1
End Sub

My ListBox is set to 1 = fmMultiSelectMulti but when I select more than one
file, only the last file selected will open. Is there something else I need
to change for it to open more than one file at a time?


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default MultiSelect ListBox

If that thought process comes over you ever again, you could go back and post a
followup saying to disregard your post.

(This doesn't happen very nice, but it's nice when it does.)

And if you're not sure which group to post, you could cross post to all (one
message to multiple newsgroups--not several messages to multiple newsgroups).
(But as you've seen, it's rarely necessary.

StephanieH wrote:

Sorry about that. I was thinking since my area of concern seemed to shift, I
should re-enter it under the new topic. I should have known you folks were
better than that and it wasn't necessary. Thanks for your help.

"Dave Peterson" wrote:

You have a reply in .misc, too.

StephanieH wrote:

I have a ListBox populated thru code as:
Sub UserForm_Initialize()
With ListBox1
.AddItem "AttyAdec"
.AddItem "2004"
.AddItem "Dialer"
.AddItem "Blank"
End With
ListBox1.ListIndex = 0
End Sub
With my OK Command as follows:
Private Sub OKButton_Click()

Msg = "You selected" & vbCrLf
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
Msg = Msg & ListBox1.List(i) & vbCrLf
End If
Next i
MsgBox Msg

If ListBox1.ListIndex = 0 Then

ChDir "C:\Documents and Settings\A092048\Desktop"
Workbooks.Open Filename:= _
"C:\Documents and Settings\A092048\Desktop\AttyAdec 090304.xls"

End If

If ListBox1.ListIndex = 1 Then

Workbooks.Open Filename:="C:\Documents and
Settings\A092048\Desktop\2004.xls"
End If

If ListBox1.ListIndex = 2 Then

Workbooks.Open Filename:= _
"C:\Documents and Settings\A092048\Desktop\Dialer.xls"
End If

Unload UserForm1
End Sub

My ListBox is set to 1 = fmMultiSelectMulti but when I select more than one
file, only the last file selected will open. Is there something else I need
to change for it to open more than one file at a time?


--

Dave Peterson


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default MultiSelect ListBox

(This doesn't happen very nice, but it's nice when it does.)
should be:
(This doesn't happen very often, but it's nice when it does.)

(stupid fingers!)

Dave Peterson wrote:

If that thought process comes over you ever again, you could go back and post a
followup saying to disregard your post.

(This doesn't happen very nice, but it's nice when it does.)

And if you're not sure which group to post, you could cross post to all (one
message to multiple newsgroups--not several messages to multiple newsgroups).
(But as you've seen, it's rarely necessary.

StephanieH wrote:

Sorry about that. I was thinking since my area of concern seemed to shift, I
should re-enter it under the new topic. I should have known you folks were
better than that and it wasn't necessary. Thanks for your help.

"Dave Peterson" wrote:

You have a reply in .misc, too.

StephanieH wrote:

I have a ListBox populated thru code as:
Sub UserForm_Initialize()
With ListBox1
.AddItem "AttyAdec"
.AddItem "2004"
.AddItem "Dialer"
.AddItem "Blank"
End With
ListBox1.ListIndex = 0
End Sub
With my OK Command as follows:
Private Sub OKButton_Click()

Msg = "You selected" & vbCrLf
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
Msg = Msg & ListBox1.List(i) & vbCrLf
End If
Next i
MsgBox Msg

If ListBox1.ListIndex = 0 Then

ChDir "C:\Documents and Settings\A092048\Desktop"
Workbooks.Open Filename:= _
"C:\Documents and Settings\A092048\Desktop\AttyAdec 090304.xls"

End If

If ListBox1.ListIndex = 1 Then

Workbooks.Open Filename:="C:\Documents and
Settings\A092048\Desktop\2004.xls"
End If

If ListBox1.ListIndex = 2 Then

Workbooks.Open Filename:= _
"C:\Documents and Settings\A092048\Desktop\Dialer.xls"
End If

Unload UserForm1
End Sub

My ListBox is set to 1 = fmMultiSelectMulti but when I select more than one
file, only the last file selected will open. Is there something else I need
to change for it to open more than one file at a time?

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
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
Multiselect Listbox use RKS Excel Discussion (Misc queries) 1 May 12th 06 03:04 PM
Multiselect Listbox Francis Ang[_3_] Excel Programming 0 October 27th 04 02:21 AM
Multiselect Listbox Francis Ang[_3_] Excel Programming 2 October 25th 04 01:57 AM
MultiSelect ListBox in Excel PeteSmith Excel Programming 1 April 20th 04 11:14 AM
multiselect listbox CG Rosén Excel Programming 2 December 28th 03 05:17 PM


All times are GMT +1. The time now is 10:20 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"