---
description: Collecting all the file names in a worksheet is very important. We will introduce a method to input all the file names into a worksheet.
title: How to Copy the List of All File Names in a Folder into Excel Worksheet via VBA
image: https://www.datanumen.com/blogs/wp-content/uploads/2017/01/1-insert-module.jpg
---

-
-
-

[Home](https://www.datanumen.com/blogs/) > [Solutions](https://www.datanumen.com/blogs/category/solutions/) > [Office Solutions](https://www.datanumen.com/blogs/category/solutions/office-solutions/) > [Excel Solutions](https://www.datanumen.com/blogs/category/solutions/office-solutions/excel-solutions/) > How to Copy the List of All File Names in a Folder into Excel Worksheet via VBA

# How to Copy the List of All File Names in a Folder into Excel Worksheet via VBA

[Excel Solutions](https://www.datanumen.com/blogs/category/solutions/office-solutions/excel-solutions/) October 3, 2025

Share Now:

-
-
-
-
-
-
-
-

*Collecting all the file names in a worksheet is very important to your work. In this article, we will introduce a method to input all the file names into a worksheet by using VBA macro.*

In our previous article [*2 Methods to Copy the List of All File Names in a Folder into Your Excel Worksheet*](https://www.datanumen.com/blogs/2-methods-copy-list-file-names-folder-excel-worksheet/), we have introduced two methods to list all the file names in a folder into a worksheet. And now we have found another method. You can also use the VBA macro to finish this task. Follow the steps below and see how to use it.

## Copy the List of All File Names in a Folder

1. Open the workbook that you need to input the file names.
2. And then press the shortcut keys “Alt +F11” on the keyboard to open the Visual Basic editor.
3. After that, click the tab “Insert” in the toolbar.
4. Next choose the option “Module” in the drop-down list. Therefore, you have inserted a new module in the editor.![Insert Module](https://www.datanumen.com/blogs/wp-content/uploads/2017/01/1-insert-module.jpg "Insert Module")
5. In this step, copy the following codes into the new module:

```
Sub ListAllFileNames()
  Dim strTargetFolder As String, strFileName As String, nCountItem As Integer

  '  Initialization
  nCountItem = 1
  strTargetFolder = "C:\Users\Sample\Desktop\Sales Volume" & "\"
  strFileName = Dir(strTargetFolder, vbDirectory)

  '  Get the file name
  Do While strFileName <> ""
    If strFileName <> "." And strFileName <> ".." Then
      Cells(nCountItem, 1) = strFileName
      nCountItem = nCountItem + 1
    End If
    strFileName = Dir
  Loop
End Sub
```

In this macro, you need to change the target folder according to your actual need. And we will input the file names into the column A in a worksheet. If you need to input the file names into other range, you can also modify the codes.

6. After that, run this macro. You can click the button “Run Sub” in the toolbar or press the button “F5” on the keyboard to run this macro.
7. Next come back to the worksheet. You will find that all the file names in the folder have already appeared in the column A.![Result]( "Result")

Compared with the other two methods in the article [*2 Methods to Copy the List of All File Names in a Folder into Your Excel Worksheet*](https://www.datanumen.com/blogs/2-methods-copy-list-file-names-folder-excel-worksheet/), you will see that using VBA macro is very convenient. However, on the other hand, if you are not familiar with Excel VBA, you will meet with errors when modifying the codes. Therefore, you can use one of the three methods according to your actual need.

## Pay Attention to Dangerous Software

You will certainly install a lot of software in your computer. And those applications can help you a lot in your work. However, some of them are dangerous applications. Once you install them in your computer, they will collect your personal information. What’s worse, your Excel files will also be damaged by them. At this moment, uninstall the dangerous software immediately. Besides, you also need to use a recovery tool to [repair damaged xlsx file](https://www.datanumen.com/excel-repair/). Thus, you can make sure that your Excel files are safe.

## Author Introduction:

Anna Ma is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including [repair Word docx file problem](https://www.datanumen.com/word-repair/) and outlook repair software products. For more information visit [www.datanumen.com](https://www.datanumen.com/)

Share Now:

-
-
-
-
-
-
-
-

[← Previous post](https://www.datanumen.com/blogs/4-ways-quickly-delete-footnotes-endnotes-word-document/)

[Next post →](https://www.datanumen.com/blogs/rename-attachments-forwarding-email-outlook/)

Comments are closed.

![Data Recovery Blog]()

Follow or like us on Facebook, LinkedIn and Twitter to get all promotions, latest news and updates on our products and company.

-
-
-

### Featured Products

- [DataNumen Outlook Repair](https://www.datanumen.com/outlook-repair/)
- [DataNumen SQL Recovery](https://www.datanumen.com/sql-recovery/)
- [DataNumen Exchange Recovery](https://www.datanumen.com/exchange-recovery/)
- [DataNumen Access Repair](https://www.datanumen.com/access-repair/)
- [DataNumen Excel Repair](https://www.datanumen.com/excel-repair/)
- [DataNumen PDF Repair](https://www.datanumen.com/pdf-repair/)
- [DataNumen Word Repair](https://www.datanumen.com/word-repair/)
- [DataNumen Zip Repair](https://www.datanumen.com/zip-repair/)

### Popular posts

```json
{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.datanumen.com\/blogs\/copy-list-file-names-folder-excel-worksheet-via-vba\/#article","isPartOf":{"@id":"https:\/\/www.datanumen.com\/blogs\/copy-list-file-names-folder-excel-worksheet-via-vba\/"},"author":{"name":"AuthorCCW","@id":"https:\/\/www.datanumen.com\/blogs\/#\/schema\/person\/33ded6c47c77587f9158d99f05e23957"},"headline":"How to Copy the List of All File Names in a Folder into Excel Worksheet via VBA","datePublished":"2017-01-10T00:56:44+00:00","dateModified":"2025-10-03T09:24:28+00:00","mainEntityOfPage":{"@id":"https:\/\/www.datanumen.com\/blogs\/copy-list-file-names-folder-excel-worksheet-via-vba\/"},"wordCount":493,"commentCount":2,"publisher":{"@id":"https:\/\/www.datanumen.com\/blogs\/#organization"},"image":{"@id":"https:\/\/www.datanumen.com\/blogs\/copy-list-file-names-folder-excel-worksheet-via-vba\/#primaryimage"},"thumbnailUrl":"https:\/\/www.datanumen.com\/blogs\/wp-content\/uploads\/2017\/01\/1-insert-module.jpg","articleSection":["Excel Solutions"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.datanumen.com\/blogs\/copy-list-file-names-folder-excel-worksheet-via-vba\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.datanumen.com\/blogs\/copy-list-file-names-folder-excel-worksheet-via-vba\/","url":"https:\/\/www.datanumen.com\/blogs\/copy-list-file-names-folder-excel-worksheet-via-vba\/","name":"How to Copy the List of All File Names in a Folder into Excel Worksheet via VBA","isPartOf":{"@id":"https:\/\/www.datanumen.com\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.datanumen.com\/blogs\/copy-list-file-names-folder-excel-worksheet-via-vba\/#primaryimage"},"image":{"@id":"https:\/\/www.datanumen.com\/blogs\/copy-list-file-names-folder-excel-worksheet-via-vba\/#primaryimage"},"thumbnailUrl":"https:\/\/www.datanumen.com\/blogs\/wp-content\/uploads\/2017\/01\/1-insert-module.jpg","datePublished":"2017-01-10T00:56:44+00:00","dateModified":"2025-10-03T09:24:28+00:00","description":"Collecting all the file names in a worksheet is very important. We will introduce a method to input all the file names into a worksheet.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.datanumen.com\/blogs\/copy-list-file-names-folder-excel-worksheet-via-vba\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanumen.com\/blogs\/copy-list-file-names-folder-excel-worksheet-via-vba\/#primaryimage","url":"https:\/\/www.datanumen.com\/blogs\/wp-content\/uploads\/2017\/01\/1-insert-module.jpg","contentUrl":"https:\/\/www.datanumen.com\/blogs\/wp-content\/uploads\/2017\/01\/1-insert-module.jpg","width":564,"height":217,"caption":"Insert Module"},{"@type":"WebSite","@id":"https:\/\/www.datanumen.com\/blogs\/#website","url":"https:\/\/www.datanumen.com\/blogs\/","name":"Data Recovery Blog","description":"Discuss every aspect of data recovery","publisher":{"@id":"https:\/\/www.datanumen.com\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.datanumen.com\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.datanumen.com\/blogs\/#organization","name":"Data Recovery Blog","url":"https:\/\/www.datanumen.com\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.datanumen.com\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/www.datanumen.com\/blogs\/wp-content\/uploads\/2019\/02\/logowithouttext.jpg","contentUrl":"https:\/\/www.datanumen.com\/blogs\/wp-content\/uploads\/2019\/02\/logowithouttext.jpg","width":296,"height":397,"caption":"Data Recovery Blog"},"image":{"@id":"https:\/\/www.datanumen.com\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataNumen","https:\/\/x.com\/DataNumen","http:\/\/www.linkedin.com\/company\/datanumen","https:\/\/myspace.com\/datanumen\/","http:\/\/www.pinterest.com\/datanumen\/","https:\/\/www.youtube.com\/channel\/UCVIIuuKfUBHSJauUaVP13tw"]},{"@type":"Person","@id":"https:\/\/www.datanumen.com\/blogs\/#\/schema\/person\/33ded6c47c77587f9158d99f05e23957","name":"AuthorCCW","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3516ed90fc242780d3947a989f895bc46e70c3e83485d30f2b457a007906aa58?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3516ed90fc242780d3947a989f895bc46e70c3e83485d30f2b457a007906aa58?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3516ed90fc242780d3947a989f895bc46e70c3e83485d30f2b457a007906aa58?s=96&d=mm&r=g","caption":"AuthorCCW"},"sameAs":["https:\/\/www.datanumen.com\/"]}]}
```
