Excel.Tips.Net ExcelTips (Menu Interface)

Merging Many Workbooks

Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Merging Many Workbooks.

Joy ran into a problem merging quite a few workbooks together. The majority of the workbooks—about 200 of them, all in a single folder—each contain a single worksheet, but some contain more. The worksheets form each of these workbooks needs to be added to a single workbook.

The easiest way to do merges of this magnitude—particularly if you have to do it often—is with a macro. The following macro displays a dialog box asking you to select the files to merge. (You can select multiple workbooks by holding down the Ctrl key as you click each one.) It loops thru the list you select, opening each one and moving all its worksheets to the end of the workbook with the code.

Sub CombineWorkbooks()
    Dim FilesToOpen
    Dim x As Integer
    Dim Outwbk As Workbook

    Set Outwbk = ActiveWorkbook

    On Error GoTo ErrHandler
    Application.ScreenUpdating = False

    FilesToOpen = Application.GetOpenFilename _
      (FileFilter:="Microsoft Excel Files (*.xls), *.xls", _
      MultiSelect:=True, Title:="Files to Merge")

    If TypeName(FilesToOpen) = "Boolean" Then
        MsgBox "No Files were selected"
        GoTo ExitHandler
    End If

    x = 1
    While x <= UBound(FilesToOpen)
        Workbooks.Open Filename:=FilesToOpen(x)
        Sheets().Move After:=Outwbk.Sheets(Outwbk.Sheets.Count)
        x = x + 1

    Application.ScreenUpdating = True
    Exit Sub

    MsgBox Err.Description
    Resume ExitHandler
End Sub

In the process of adding the worksheets to the end of the workbook, Excel will automatically append a (2), (3), etc. when duplicates worksheet names are detected. Any formulas in the book referring to other sheets will also be updated to reflect the new names.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2409) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Merging Many Workbooks.

Related Tips:

Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!


Leave your own comment:

  Notify me about new comments ONLY FOR THIS TIP
Notify me about new comments ANYWHERE ON THIS SITE
Hide my email address
*What is 5+3 (To prevent automated submissions and spam.)
           Commenting Terms

Comments for this tip:

Kiara    06 Feb 2015, 13:22
can any one of you please provide me code for merging sheet 1 of all excel sheets, sheet 2 of all excel sheets and so on in 1 workbook.
unokashi    05 Dec 2014, 03:56
Can you please help me with my question.
1. There is a common template which has some tasks listed in columns against which the team members will update the time taken (effort) for each task in the entire month.
2. There are different levels of team members (Entry, Intermediate, Specialist, etc.).
3. The template has multiple sheets, but I need to pick the data from only one specific sheet of the workbook. So in the solution I am looking for, it would be good to have an option to select the required sheet in that workbook.
4. The template has the common tasks listed in the Columns (Say A25 to A156) and on the rows there are these levels (Entry - Cell B24, Inter - Cell C24, Spe - Cell D24, etc) mentioned under which depending on his/ her level, the team member enters the time (effort) for each task [so if he/ she is and Entry, they will enter values (Effort) in B25 to B150 cells]. There are chances that the cells can be empty for few of the tasks also.

Task 1 2
Task 2 4
Task 3 5
Task 4
Task 5 12
Task 6 22
Task 7 1
Task 8
Task 9 4
Task 10 5
Task 11 1
Task 12 12
Task 13
Task 14 1
Task 15 12
Task 16
Task 17 1

5. Each of the team member submits one excel work book with the entries for the entire month based on his level, so I will have multiple such work books in the name of each team member.

The need:
I have a master file which has the same tasks listed in columns and same levels mentioned in the rows. I need to consolidate by adding the effort taken for each task against each level.

A macro with the following would help:
1. An option to specify the path of the folder in which all the excel files contain.
2. A button to 'Update' in the master sheet.
sundar    17 Mar 2013, 23:19
Great, but with this code the opened files were not merged!!!!!!
CdeBruin    17 Mar 2013, 02:31
Hi Allen,

Confirm that when the While...Wend loop ends, Joy's 200 spread sheets are still open.

This could :
1) Use unnecessary resources
2) Require all 200 to be closed manually

so would I be correct to suggest that after the x = x + 1, one could add….(assuming that the source is the “Active” workbook)

ActiveWorkbook.Close SaveChanges:=False

If I am correct, then each workbook would be closed within the loop.

Many thanks for all the great tips:-)
Regards Corrie

Our Company

Sharon Parq Associates, Inc.

About Tips.Net

Contact Us


Advertise with Us

Our Privacy Policy

Our Sites


Beauty and Style




DriveTips (Google Drive)

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)



Home Improvement

Money and Finances


Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Our Products

Helpful E-books

Newsletter Archives


Excel Products

Word Products

Our Authors

Author Index

Write for Tips.Net

Copyright © 2016 Sharon Parq Associates, Inc.