File directory into a listbox

R

Richard Edwards

All,

In listbox1 I am trying to retreive the contents of directory
"k:\files\*.csv" and am having real problems in doing this.

Can anyone give me the quick answer.

Thank you.

Richard
 
C

Chip Pearson

Richard,

Try something like

Private Sub CommandButton1_Click()
Dim FName As String
With Me.ListBox1
.Clear
FName = Dir("k:\files\*.csv")
Do Until FName = ""
.AddItem FName
FName = Dir()
Loop
End With
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
R

Richard Edwards

Thank you very much. Spot on!

Just another quick question that I forgot to ask 1st time round. How do I go
about using the file I have highlighted?

ie: variable = listbox1.selection(?)

Thank you.

Richard
 
C

Chip Pearson

Richard,

To get the selected file in the list box, use

With Me.ListBox1
If .ListIndex >= 0 Then
Variable = .List(.ListIndex)
End If
End With


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
R

Richard Edwards

Got it. Thank you.


Chip Pearson said:
Richard,

To get the selected file in the list box, use

With Me.ListBox1
If .ListIndex >= 0 Then
Variable = .List(.ListIndex)
End If
End With


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


I
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top