To import multiple text files into Excel at once, use the Get Data from Folder feature within Power Query. This method allows you to point Excel to a specific folder, automatically identify all compatible text or CSV files within it, and stack them into a single table without needing to open each file individually. This is the most efficient way to handle bulk data imports because it creates a dynamic link; if you add new text files to that folder later, you simply click Refresh to update your spreadsheet.

What You'll Need

  • Microsoft Excel (Office 365 or Excel 2016 and newer are recommended for the full Power Query interface).
  • A dedicated folder on your computer or network drive containing only the text files you wish to import.
  • Text files (.txt or .csv) that share a consistent structure, meaning they have the same columns and delimiters.

Step-by-Step

  1. Organize Your Source Files: Before opening Excel, move all the text files you want to import into one single folder. Ensure that no other file types (like PDFs or Word documents) are in this folder, as Excel will attempt to process every file it finds, which can lead to import errors.
  2. Initiate the Data Connection: Open a blank Excel workbook. Go to the Data tab on the top ribbon. In the Get & Transform Data group, click on Get Data, then hover over From File and select From Folder. (Note: Menu labels may vary slightly depending on your version of Excel or region).
  3. Browse to the Folder: A file explorer window will appear. Navigate to the folder where you stored your text files, select the folder, and click Open.
  4. Preview the File List: Excel will now display a preview window listing every file found in that folder. You will see columns for Name, Extension, Date accessed, and Folder Path. Do not click Load yet, as this would only import the list of filenames, not the actual data inside the files. Instead, click the Combine dropdown button at the bottom of the window and select Combine & Transform Data.
  5. Configure the File Import Settings: The Combine Files dialog box will open. Excel uses the first file in the folder as a "Sample File" to determine how the rest should be imported. Check the following settings:
    • File Origin: Ensure the character encoding (e.g., UTF-8) matches your files so special characters display correctly.
    • Delimiter: Select whether your files are separated by commas, tabs, semicolons, or a custom character.
    • Data Type Detection: Choose whether Excel should detect data types based on the first 200 rows or the entire dataset.
    Once the preview looks correct, click OK.
  6. Refine Data in Power Query Editor: You are now in the Power Query Editor window. Excel has automatically added a column called "Source.Name," which tells you which file each row of data came from. This is useful for auditing. From here, you can:
    • Remove unnecessary columns by right-clicking the header and selecting Remove.
    • Filter out blank rows or header rows that may have been repeated from the multiple files.
    • Change data types (e.g., changing a column from Text to Decimal Number) by clicking the icon next to the column header.
  7. Load the Data to Excel: Once the data is cleaned and formatted, go to the Home tab in the Power Query Editor and click Close & Load. Excel will now import all the combined data from the text files into a formatted Table in your worksheet.

Common Mistakes

One of the most frequent errors is including files in the source folder that do not match the structure of the primary data files. For example, if you have ten CSV files with five columns and one CSV file with three columns, Power Query may throw an error or create a massive amount of "null" values because the columns do not align. Always keep your import folder "clean."

Another common mistake is forgetting to check the delimiter. If your files are tab-delimited but you leave the setting on "Comma," Excel will put the entire line of text into a single column, making the data impossible to analyze. Always verify the preview window in the Combine Files dialog before proceeding.

Users also often click "Load" instead of "Combine & Transform." Loading the folder directly only gives you a metadata list of the files (their names and sizes). To get the actual content of the files, you must use the Combine function.

Tips

To make your workflow truly automated, name your source folder something generic like "Monthly_Reports." Whenever you receive a new text file for the next month, simply drop it into that folder. You do not need to repeat the entire import process; just go to the Data tab in Excel and click Refresh All. Excel will re-scan the folder, find the new file, and append it to the bottom of your existing table.

If your files have headers that are repeated in every single file, Power Query usually handles this automatically during the Combine process. However, if you see repeated headers in your final table, use the filter arrow on the column header in the Power Query Editor to uncheck the name of the header row. This removes all instances of that header across all imported files simultaneously.

For very large datasets (hundreds of thousands of rows), instead of clicking "Close & Load," click the arrow under it and select Close & Load To.... Then, choose Only Create Connection and check the box for Add this data to the Data Model. This allows you to analyze the data using Pivot Tables without slowing down your workbook by loading millions of cells into the grid.

Troubleshooting

If you receive a "Data Format Error": This usually happens when a column contains a value that doesn't match the assigned data type (e.g., a word in a column designated as "Currency"). To fix this, go back into the Power Query Editor (Data > Queries & Connections > Right-click your query > Edit), find the column with the error, and change the data type to "Text" to see what the problematic value is.

If files are missing from the import: Check the file extensions. Power Query is sensitive to the file type selected. If some files are .txt and others are .csv, you may need to ensure the folder filter is set to include both or standardize all files to one format before importing.

If the "From Folder" option is missing: Ensure you are using a version of Excel that supports Power Query. In Excel 2010 or 2013, Power Query was a separate add-in that had to be downloaded and installed. In 2016 and later, it is built-in under the Data tab. If you are using Excel for the Web, some advanced "Get Data" features are limited; use the desktop application for the initial setup.

If the data is shifted or misaligned: This is almost always a delimiter issue. Go back to the Combine Files step and double-check if the files use a comma, semicolon, or tab. If the files use a mix of different delimiters, you will need to standardize them first, as Power Query applies one set of rules to all files in the folder.

Frequently Asked Questions

Can I import files from a cloud folder like OneDrive?

Yes, as long as the OneDrive folder is synced to your local computer via the OneDrive app. You can point Excel to the local synced path on your hard drive, and it will work exactly as described.

What happens if I delete a file from the folder after importing?

The data will remain in your Excel sheet until you hit the Refresh button. Once you refresh, Excel re-scans the folder; if a file is gone, those rows will be removed from the table.

Is there a limit to how many files I can import at once?

There is no hard limit on the number of files, but there is a limit on the total number of rows Excel can display in a single worksheet (1,048,576 rows). If your combined files exceed this, you must load the data to the "Data Model" instead of the worksheet.

Do all the text files need to have the same name?

No, the filenames can be completely different. Power Query identifies the files by their location in the folder, not by their name. It will simply stack the data from each file regardless of what the file is called.

Can I filter which files are imported from the folder?

Yes. In the Power Query Editor, before you click the Combine button, you can use the filter arrow on the "Name" or "Extension" columns to exclude specific files (e.g., excluding any file that contains the word "Draft" in the filename).