ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE. Software > Finished Programs

DONE: Group of Excel files in folder, send all first rows to a text file (or other)

(1/2) > >>

I need to vertically concatenate around 100 Excel files (xls) -- using a program called "Merge Excel Files."

That program assumes all files are structured the same, same column headers extending across in each file.

I must double-check that, though.

Assume 100 xls files in a single folder.  I'd like to find a way to copy the first row -- the column headers -- of every xls file over into, say, a text file.  Then in a text editor (with word wrap off) I can easily peruse down making sure all column headers are as they should be -- each column in the text file will have only one particular label.

One possible solution would be to use Skwire's ClipTrap.  Load each of the 100 xls files one at a time, highlight the first row, copy.  But this would take some time.

Hoping someone can come up with an easier way.


Nicholas Kormanik

Found basically the same question here:

With the following vba (?) code solution:

Sub FirstRow()
    Application.DisplayAlerts = False
    Dim strFilename As String
    Dim strPath As String
    Dim wbMaster As Workbook
    Dim wsMaster As Worksheet
    Dim wbFiles As Workbook
    Dim i As Integer

    i = 1
    Set wbMaster = ThisWorkbook
    Set wsMaster = wbMaster.Sheets(2)
    strPath = "C:\path\to\your\files\"
    strFilename = Dir(strPath & "*.xls")

    Do While strFilename <> ""
        Set wbFiles = Workbooks.Open(strPath & strFilename, False)
        wsMaster.Cells(RowIndex:=i, ColumnIndex:=1).PasteSpecial Paste:=xlPasteAll
        wbFiles.Close (False)
        strFilename = Dir
        i = i + 1
    Application.DisplayAlerts = True
End Sub

"A couple of things to note:
- You'll want to change the Sheet(x) references to the appropriate values for your needs
- Ensure there is a "\" at the end of strPath when you put in your own path
- I've turned DisplayAlerts to false during the execution to avoid a pop-up on every file asking if you want to clear the clipboard or not."

Unfortunately I don't understand how to use his solution.  Wish he had have given an example, or explained it more extensively.

Hi, Nick.  Any idea on the maximum number of columns you will be dealing with?

Max number of columns would be 250.

That large number means it'll be lots of work without some magic.

Max number of columns would be 250.
That large number means it'll be lots of work without some magic.-nkormanik (April 09, 2013, 08:18 PM)
--- End quote ---

Please give this a try:

Close all open Excel files and make a folder with copies of your working files.  Put the NKExcelTool.exe in the same folder as your copies and run it.  A progress bar should appear and, once it's finished, it should display a message box asking if you'd like to open the text output file.  The first row of each Excel file should be listed along with the source filename in brackets at the end of each line.  That way, if there is a discrepancy, you'll be able to tell which file is the culprit.  This application uses COM for the grunt work which can be somewhat finicky so let me know how it goes.  Thanks.


[0] Message Index

[#] Next page

Go to full version