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

Inserting Tomorrow's Date

You can use a couple of different worksheet functions to enter today's date in a cell. What if you want to calculate ...

Discover More

Inserting the Document Revision Number

Need to know how many times your document has been saved? Word keeps track of this information, and makes it easily ...

Discover More

Changing a Docs Style

Docs provides nine pre-defined styles you can apply to the text in a document. If you want a particular style to use a ...

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)

Getting Rid of Extra Quote Marks in Exported Text Files

If you don't like the way that Excel exports information you intend to use with other programs, then your best bet is to ...

Discover More

Aligning Cells when Importing from CSV

When you import information from a CSV text file, Excel formats the data according to its default settings. Wouldn't it be ...

Discover More

Opening a Workbook with Two Windows

If you open a workbook and notice that Excel displays two windows for it, this has to do with how the workbook was saved. ...

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 7 - 0?

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.