Merge Multiple workbooks into one workbook

Grimm127

Board Regular
Joined
Aug 17, 2011
Messages
132
Hi All,

I found this code online. For the most part it works to what I want it to do. But there are a couple of issues.

1 - I would like to add code where I can open a window to select where all the multiple files are located not just hardcoded.
2 - The line of code where I asking to Identify the name of the file where the data is coming from (Booklist name) places the name of the file in column O which is an empty column with the exception of the header. I would like the name to land in Column W after the last column in the Range (Column ). When the file has no data but the header the code works fine by placing the name of the file in column W.
3 - Last Issue, After the Macro is done running a pop up window appears Data Link Properties. It is listing the folder location as the data source. I have no idea why this keeps popping up. I just cancel because the data does tie correctly. I would like it to stop popping up.

I really appreciate some direction on this. I have a general knowledge of VBA but by no means an expert.
Thank you in Advance!


Sub MergeAllWorkbooks()

Dim bookList As Workbook
Dim mergeObj As Object, dirObj As Object, filesObj As Object, everyObj As Object
Application.ScreenUpdating = False
Set mergeObj = CreateObject("Scripting.FileSystemObject")


' Create a new workbook and set a variable to the first sheet.
Set SummarySheet = Workbooks.Add(xlWBATWorksheet).Worksheets(1)

'change folder path of excel files here
Set dirObj = mergeObj.Getfolder("PASTE FOLDER PATH HERE")
Set filesObj = dirObj.Files
For Each everyObj In filesObj
Set bookList = Workbooks.Open(everyObj)

'change "A2" with cell reference of start point for every files here
'for example "B3:IV" to merge all files start from columns B and rows 3
'If you're files using more than IV column, change it to the latest column
'Also change "A" column on "A65536" to the same column as start point
Range("A6:V" & Range("A65536").End(xlUp).Row).Copy
ThisWorkbook.Worksheets(1).Activate

'Do not change the following column. It's not the same column as above
Range("A65536").End(xlUp).Offset(1, 0).PasteSpecial
Range("A65536").End(xlUp).End(xlToRight).Offset(0, 1).Cells.Value = bookList.Name
Application.CutCopyMode = False
bookList.Close

Next


' Call AutoFit on the destination sheet so that all
' data is readable.
SummarySheet.Columns.AutoFit


End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top