Populate Listindex (with 2 columns) with files and its Path/location in directory

haseft

Active Member
Joined
Jun 10, 2014
Messages
321
Hi,
i want to Populate Listindex (with 2 columns) with files and its Path/location in directory
I can mange to get all files name i Listbox' but not the second column, I don,t know how to get it.
for example:
(column 1) School in London (column 2) R:\Education\School\Region\School in north.pdf
a.s.o
VBA Code:
Private Sub CommandButton10_Click()
'
Dim MyFolder As String
Dim MyFile As String
Dim j As Integer
MyFolder = "R:\Education\School\Region"
MyFile = Dir(MyFolder & "\*.*")
Do While MyFile <> ""
    Page6ListBox2.AddItem MyFile
    MyFile = Dir
Loop

End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
How about
VBA Code:
Private Sub CommandButton1_Click()
'
Dim MyFolder As String
Dim MyFile As String
Dim j As Integer
MyFolder = "R:\Education\School\Region"
MyFile = Dir(MyFolder & "\*.*")
Do While MyFile <> ""
    With Page6ListBox2
      .AddItem MyFile
      .List(.ListCount - 1, 2) = MyFolder & "\" & MyFile
    End With
    MyFile = Dir
Loop

End Sub
 
Upvote 0
How about
VBA Code:
Private Sub CommandButton1_Click()
'
Dim MyFolder As String
Dim MyFile As String
Dim j As Integer
MyFolder = "R:\Education\School\Region"
MyFile = Dir(MyFolder & "\*.*")
Do While MyFile <> ""
    With Page6ListBox2
      .AddItem MyFile
      .List(.ListCount - 1, 2) = MyFolder & "\" & MyFile
    End With
    MyFile = Dir
Loop

End Sub

hi Fluff
I get only one column with files name, the second column is empty,
the second column shuold be ex. R:\Education\School\Region\School in north.pdf
 
Upvote 0
Oops, it should be
VBA Code:
.List(.ListCount - 1, 1) = MyFolder & "\" & MyFile
 
Upvote 0
Solution
Have you change the listbox to have two columns?
 
Upvote 0
Or at once

VBA Code:
Sub jec()
 Dim it As Variant, x As Long
 ReDim ar(1, 0) As Variant
 
 For Each it In CreateObject("Scripting.filesystemobject").getfolder("C:\Users\xxx\xx\xx\xxx\").Files
   ReDim Preserve ar(1, x)
   ar(0, x) = it.Name
   ar(1, x) = it.Path
   x = x + 1
 Next
 Page6ListBox2.List = Application.Transpose(ar)
End Sub
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,899
Messages
6,122,155
Members
449,068
Latest member
shiz11713

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top