Professional Documents
Culture Documents
How To Combine Multiple Workbooks Into One Excel Workbook
How To Combine Multiple Workbooks Into One Excel Workbook
Excel Workbook
I got a call from a friend who wanted to combine multiple workbooks into one workbook. He had a lot of
workbooks in a folder and he wanted to get all the worksheets from all the workbooks into one single
workbook. While this can be done manually, it would be time-consuming and error-prone.
However, a simple VBA code can do this in a few seconds.
Put all the Excel files that you want to combine into a folder. For the purpose of this tutorial, I
have created a folder named Test and have six files in it (4 Excel workbooks and 1 Power Point
and Word each).
Press ALT + F11 (or go to Developer > Code > Visual Basic). This will open the Visual Basic
Editor.
In the VB Editor, in the Project Editor, right-click on any of the objects for the workbook and go to
Insert > Module. This will insert a module for the workbook.
Double click on the module. It will open the code window on the right.
Copy and paste the above code into the code window.
In this line, change the part in double quotes (highlighted in orange) with the location of the folder
in which you have the files that you want to combine. In the code used above, the folder is on the
Desktop. In case you have it in some other location, specify that path here.
Place the cursor anywhere in the code and click on the green play button in the Toolbar options (or
The code uses the DIR function to get the file names from the specified folder.
The following line assigns the first excel file name to the variable Filename.
Filename = Dir(FolderPath & *.xls*)
Then the Do While loop is used to check whether all the files have been covered.
Within the Do While loop, For Each loop is used to copy all the worksheets to the workbook
in which we are running the code.
At the end of the Do Loop, following line of code is used: Filename = Dir(). It assigns the next
Excel file name to the Filename variable and the loop starts again.
When all the files are covered, DIR function returns an empty string, which is when the loop ends.