Automatic file name list in Excel

Paddy123

New Member
Joined
Dec 27, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
Hi there, i once got shown an Excel sheet that had a button, that once clicked took you to file explorer, you then clicked on the file you wanted and it generated a list of the file names automatically. I am looking to recreate this but don't know where to start, everthing i google has a step where you have to copy and paste the files and then go from there, but i am looking for it to be done just from Excel. Can anyone help?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Don’t you mean click on a folder and then give you the list of all files(not only xls files) in this folder (and subfolders?)
 
Upvote 0
VBA Code:
Dim oFSO As Object, ar(2000, 0), x As Long

Sub jec()
 Set oFSO = CreateObject("Scripting.FileSystemObject")
 With Application.FileDialog(4)
   If .Show = 0 Then Exit Sub
   GetFiles .SelectedItems(1)
   If x Then Cells(2, 2).Resize(x) = ar
   Erase ar: x = 0
 End With
End Sub

Sub GetFiles(xFold)
 Dim Obj As Object
 If Right(xFold, 1) <> "\" Then xFold = xFold & "\"
 With oFSO.GetFolder(xFold)
    For Each Obj In .Files
       ar(x, 0) = Obj.Name
       x = x + 1
    Next
    For Each Obj In .SubFolders
       GetFiles xFold & Obj.Name
    Next
 End With
End Sub
 
Upvote 0
Don’t you mean click on a folder and then give you the list of all files(not only xls files) in this folder (and subfolders?)
yes exactly, all file names in the folder and subfolder.
 
Upvote 0
Ok, create a new module and paste this complete code. Then run macro jec and it should work as desired.
 
Upvote 0

Forum statistics

Threads
1,215,131
Messages
6,123,223
Members
449,091
Latest member
jeremy_bp001

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