Please Note: This article is written for users of the following Microsoft Excel versions: 2007 and 2010. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Importing Many Files Into Excel.

Importing Many Files Into Excel

by Allen Wyatt
(last updated June 17, 2015)

8

Andrew asked if there is a way to import many different files into Excel, all using the same import specifications. For instance, when you choose to import a comma-delimited text file, Excel's import filter asks you a series of questions about how the import should be done. If you are importing a single file, this is not a problem. If you have fifty or sixty files to import, answering the questions over and over again can get very tedious very quickly.

The short answer is that there is no way to do a "mass import" in Excel. Some questions asked by the import filter simply need to be asked for each file. The only way around this is to create your own "import" process using a macro. The macro can either open the source file itself, or it can answer the Import Wizard questions, as it sees fit.

Of course, writing such a macro can be a daunting exercise. It is beyond the scope of ExcelTips to attempt such a macro, particularly since the process to be followed during the import can vary so much from one type of input file to another.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (12080) applies to Microsoft Excel 2007 and 2010. You can find a version of this tip for the older menu interface of Excel here: Importing Many Files Into Excel.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Detecting Types of Sheets in VBA

When processing workbook information in a macro, you may need to step through each worksheet to make some sort of changes. It ...

Discover More

Relative References to Cells in Other Workbooks

When you construct a formula and click on a cell in a different workbook, an absolute reference to that cell is placed in the ...

Discover More

Creating a Boilerplate Document

If you have several boilerplate documents you need to routinely use in Word, then you should learn how to use templates. They ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

Correctly Saving Delimited Files

Delimited files are often created through Excel so that your data can be exported to other programs. If the delimited data ...

Discover More

Saving in Two Locations

When you save a workbook to disk, you may want to automatically save a duplicate workbook in a separate location. This can be ...

Discover More

Locked File Puzzle

What would you do if every time you opened a workbook Excel told you it was locked? Here's how you can try to recover from ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 3 + 8?

2015-06-17 13:40:42

Matthew McCormack

This web page has a nice VBA script that can be easily adapted, http://www.mrexcel.com/forum/excel-questions/516989-import-data-multiple-text-files-multiple-sheets-excel.html


2015-06-17 13:31:29

Donald Parish

The Power Query add-in is how I would solve this today. One of the choices is to import all the text files in a folder into a single table. Can also with Excel workbooks with some modification of the Power Query Language (M) code.


2015-06-17 12:43:08

Wulflyng

For things like comma delimited files, I find it much easier to concatenate them in DOS (well, the command window).

The expression

For %g in (*.txt) do type %g >> all.txt

will give you a file called all.txt that contains all the content of the other files.

I don't know if there are limits to how big a file excel can import at once, but I haven't run into a problem doing this.


2015-06-17 10:24:24

NH

It's definitely possible to import multiple files. I found a good way to do it is record a macro for one file and assuming the rest are in a similar format, use the same code to import the other files which are all semi colon delimited. I used some additional code from another example on this site to trim all the data to clean up any leading or trailing blank spaces. If you had files in different formats I could definitely see the problem with trying to code it but if the files are in the same layout type it's not impossible. In my case I am able to import about 7 semi colon delimited text files in to Excel then export it out to a preformatted Excel report.


2015-06-17 08:15:25

balthamossa2b

Oops, small editing typo, but ChDir should be the same as the one in the FileName obviously.


2015-06-17 08:13:11

balthamossa2b

Actually it isn't that hard. You can use the macro recorder to see what the code looks like when importing a file. I just imported a .txt and here are the results:

Sub Macro1()
'
' Macro1 Macro
'

'
Application.WindowState = xlNormal
ChDir "D:safont-gregoriDesktop"
Workbooks.OpenText Filename:="D:meDesktoptest.txt", _
Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
TrailingMinusNumbers:=True
End Sub


With some patience, you can see what variable does what. Also, you should add a couples of lines saying that you want to copy Sheet(1) to a proper Workbook (since when importing a file, Excel doesn't create a new .xlsx to it, it modifies the actual file).

Once the code for one file is ready, you just need to loop through all files in a folder, which isn't particularly hard.


2015-06-17 08:09:28

Oscar

You can create a sheet that specifies file name, folder, cell ranges to be imported and cell ranges where they should be pasted.

Then you can loop through each file and perform the copy paste using the indicated cells.

I inherited this system from a coworker and it works very well.
Not sure whether it's the most efficient but it's very customizable as each file can have different range sizes.


2012-09-15 08:16:50

GP

Try an excel add on called ASAP utilities. That should do the trick.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.