Excel File Directory

wienker

New Member
Joined
Feb 25, 2003
Messages
35
Hi,

I was wondering if there was a way to have excel look into a folder and identify all the excel files in that folder. i.e. a vaildation drop-down that shows every file in the folder so I can choose which one to add.

I have a hundred or so files in a folder and am constantly adding new ones.

Any thoughts?

Thank you
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
This doesn't exactly answer your question, but I use this to search for .xls files in a folder:

Code:
Sub test()
Dim Bk As Workbook, i As Integer

With Application.FileSearch
    .NewSearch
    .LookIn = "C:\" 'folder to be searched
    .SearchSubFolders = False
    .Filename = "*.xls"
    .MatchTextExactly = True
    .FileType = msoFileTypeAllFiles
End With

With Application.FileSearch
    If .Execute() > 0 Then
        For i = 1 To .FoundFiles.Count
            'code to add file name to list box would go here
        Next i
    Else
        MsgBox "No files found."
    End If
End With

End Sub
 
Upvote 0

wienker

New Member
Joined
Feb 25, 2003
Messages
35
Thank you Kristy! I am not exactley sure what to place in the part where you stated:
'code to add file name to list box would go here

If I just wanted to paste the results on my worksheet. Is there an easy way to do that. Please let me know if you have any thoughts. Thanks again.

Cheers :biggrin:
 
Upvote 0

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
Putting them on the sheet is easy.

This should make a list in column A of the active sheet:

Code:
Sub test()
Dim Bk As Workbook, i As Integer, x As Long

x = 1

With Application.FileSearch
   .NewSearch
   .LookIn = "C:\" 'folder to be searched
   .SearchSubFolders = False
   .Filename = "*.xls"
   .MatchTextExactly = True
   .FileType = msoFileTypeAllFiles
End With

With Application.FileSearch
   If .Execute() > 0 Then
      For i = 1 To .FoundFiles.Count
         Cells(x, 1).Value = .FoundFiles(i)
         x = x + 1
      Next i
   Else
      MsgBox "No files found."
   End If
End With

End Sub
 
Upvote 0

wienker

New Member
Joined
Feb 25, 2003
Messages
35
Thanks

Thank you a ton. That's exactley what i needed. You just made my life a lot easier!!!

Have a great night. :biggrin:
 
Upvote 0

Forum statistics

Threads
1,195,662
Messages
6,010,988
Members
441,579
Latest member
satishrazdhan

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
Top