Listbox fill

  • Thread starter Thread starter Billy Banter
  • Start date Start date
B

Billy Banter

Hello all,
I want a list box that has all the names of files located in a directory. Is
this possible?

eg C:\Documents and Settings\Administrator\My Documents\*.jpg

Regards
Richard
 
Hi,

You can use the FileSearch object as follows:

Dim fs As Office.FileSearch
Dim i As Integer
Set fs = Application.FileSearch
Me.lstFiles.RowSourceType = "Value List"
With fs
.LookIn = "C:\Documents and Settings\Administrator\My Documents\My
Pictures"
.SearchSubFolders = True
.FileName = "*.jpg"
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
Me.lstFiles.AddItem .FoundFiles(i)
Next i
End If
End With

You would need to add a reference to the Office Object Library.

HTH

--

Cheers
Mark

Free Access/Office Add-Ins at:
http://mphillipson.users.btopenworld.com/
 
Back
Top