Skip to main content

How to import multiple file names into cells in Excel?

Supposing you have a folder with hundreds of files, and now, you want to import these file names into cells of a worksheet. Copying and pasting one by one will spend much time, in this article, I will talk about some quick tricks to help you import multiple file names from a folder into a worksheet.

Import multiple file names into worksheet cells with VBA code

Import multiple file names into worksheet cells with Kutools for Excel


Import multiple file names into worksheet cells with VBA code

The following VBA code can help you import the file names, file extensions and folder name into the worksheet cells, please do with following steps:

1. Launch a new worksheet that you want to import the file names.

2. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.

3. Click Insert > Module, and paste the following code in the Module Window.

VBA code: Import multiple file names into cells of worksheet

Sub GetFileList()
'updateby Extendoffice
    Dim xFSO As Object
    Dim xFolder As Object
    Dim xFile As Object
    Dim xFiDialog As FileDialog
    Dim xPath As String
    Dim i As Integer
    Set xFiDialog = Application.FileDialog(msoFileDialogFolderPicker)
    If xFiDialog.Show = -1 Then
        xPath = xFiDialog.SelectedItems(1)
    End If
    Set xFiDialog = Nothing
    If xPath = "" Then Exit Sub
    Set xFSO = CreateObject("Scripting.FileSystemObject")
    Set xFolder = xFSO.GetFolder(xPath)
    ActiveSheet.Cells(1, 1) = "Folder name"
    ActiveSheet.Cells(1, 2) = "File name"
    ActiveSheet.Cells(1, 3) = "File extension"
    i = 1
    For Each xFile In xFolder.Files
        i = i + 1
        ActiveSheet.Cells(i, 1) = xPath
        ActiveSheet.Cells(i, 2) = Left(xFile.Name, InStrRev(xFile.Name, ".") - 1)
        ActiveSheet.Cells(i, 3) = Mid(xFile.Name, InStrRev(xFile.Name, ".") + 1)
    Next
End Sub

4. Then press F5 key to execute this code, and in the popped out Browse window, choose the folder that you want to import the file names form, see screenshot:

doc import filenames 1

5. And then click OK button, and you will get the following result:

doc import filenames 2

Note:If there are subfolders within your specific folder, the file names in the subfolders will not be imported.


Import multiple file names into worksheet cells with Kutools for Excel

If you need to import the file names both in the folder and the subfolders, please don’t worry, with Kutools for Excel’s Filename List utility, you can easily import all the file names in the specific folder including the subfolders.

Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. 

After installing Kutools for Excel, please do as follows:

1. Click Kutools Plus> Import & Export > Filename List, see screenshot:

2. In the Filename List dialog box, do the following operations:

(1.) Click doc import filenames 5 button to select the folder with the files you want to import;

(2.) Check Include files in subdirectories to import the filenames of the subfolders;

(3.) Specify the files type you want to import under the Files type section;

(4.) Select one file size unit you want to display from the File size unit section;

(5.) If you want to hyperlink the filenames and folders, please check Create hyperlinks option.

doc import filenames 4

3. After finishing the settings, please click OK button, and the filenames both in folder and subfolders are imported into a new worksheet as following screenshot shown:

doc import filenames 6

Tips: If you just want to import one specified type file names from specific folder, you can check Specify option in the Filename List dialog, and type the file extension into it, then it will only import the specified type file names from both folder and subfolders.

Click to know more about this Filename List feature…

Download and free trial Kutools for Excel Now !


Demo: Import multiple file names into worksheet cells with Kutools for Excel

Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. Download and free trial Now!

Related articles:

How to list all files in folder and subfolders into a worksheet?

How to list all filenames in a folder and create hyperlinks for them in Excel?

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Comments (14)
Rated 5 out of 5 · 1 ratings
This comment was minimized by the moderator on the site
very helpful. Tnx much
Rated 5 out of 5
This comment was minimized by the moderator on the site
Another easy method is there. Just copy the directory path where you have saved the documents, and paste that link in browser (chrome/mozilla). You will get the name list and just copy paste into excel. Cheers!
This comment was minimized by the moderator on the site
i want to add table,only folder name,and data modified as well?
This comment was minimized by the moderator on the site
Hello,
Do you want to list all folder names from a specific main folder? Please give your problem more detailed.
This comment was minimized by the moderator on the site
i want to mention only folder name.what is vba code for that.
This comment was minimized by the moderator on the site
is there a way to put the folder path already in the code?
This comment was minimized by the moderator on the site
For the VBA code, how would you pull in the date modified as well?
This comment was minimized by the moderator on the site
Hello,
Add the date modified column for the imported filenames, please apply the following VBA code, please try it, hope it can help you!

Sub GetFileList()
Dim xFSO As Object
Dim xFolder As Object
Dim xFile As Object
Dim xFiDialog As FileDialog
Dim xPath As String
Dim i As Integer
Set xFiDialog = Application.FileDialog(msoFileDialogFolderPicker)
If xFiDialog.Show = -1 Then
xPath = xFiDialog.SelectedItems(1)
End If
Set xFiDialog = Nothing
If xPath = "" Then Exit Sub
Set xFSO = CreateObject("Scripting.FileSystemObject")
Set xFolder = xFSO.GetFolder(xPath)
ActiveSheet.Cells(1, 1) = "Folder name"
ActiveSheet.Cells(1, 2) = "File name"
ActiveSheet.Cells(1, 3) = "File extension"
ActiveSheet.Cells(1, 4) = "Date last modified"
i = 1
For Each xFile In xFolder.Files
i = i + 1
ActiveSheet.Cells(i, 1) = xPath
ActiveSheet.Cells(i, 2) = Left(xFile.Name, InStrRev(xFile.Name, ".") - 1)
ActiveSheet.Cells(i, 3) = Mid(xFile.Name, InStrRev(xFile.Name, ".") + 1)
ActiveSheet.Cells(i, 4) = CDate(xFile.datelastmodified)
Next
End Sub
This comment was minimized by the moderator on the site
Thanks. It was awesome
This comment was minimized by the moderator on the site
saya coba yg pake vba di run bisa tapi pas di step browser nya bukan oke tapi open terus sampai ke file tertentu dan ketika di klik malah run time 26 path not found bisa bantu kenapa itu bisa terjadi?
This comment was minimized by the moderator on the site
Apakah bisa merename file dengan excel?
terimakasih sangat membantu perkerjaan saya,
This comment was minimized by the moderator on the site
Very helpful, thank you!
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations