Display a list of Excel files at a specific location

bruty

Active Member
Joined
Jul 25, 2007
Messages
451
Is there any way in Excel to create a list of all Excel files in a given network address?

ie If cell A1 has the network address 'C:\File List\' I am looking for some code or some other way to list in the cells underneath all the Excel files in that directory.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Upvote 0
This should do what you want.
B3 should have the path. C3 should have .xls
Creates a textfile on your C: drive



Dim SearchPath As String
Dim SearchSuffix As String

SearchPath = Range("B3").Value
SearchSuffix = Range("c3").Value

Set fs = Application.FileSearch
With fs
.LookIn = SearchPath
.SearchSubFolders = True
.FileName = SearchSuffix

If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."

Open "h:\excellist.txt" For Output As #1
For i = 1 To .FoundFiles.Count
Print #1, .FoundFiles(i)
Next i
Close #1
MsgBox "c:\excellist.txt updated"

Else
MsgBox "There were no files found."
End If
End With
'
End Sub
 
Upvote 0

Forum statistics

Threads
1,211,710
Messages
6,103,451
Members
447,866
Latest member
bowers261

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