Ever Wonder to Copy all the Workbooks into one Workbook.
In this post i will share the script to copy all the excel files from one folder to Single Excel File.
Below is the Script
Sub MergeMultipleWorkbooks()
'Define Variables
Dim Path, FileName As String
'Assign Values to Variables
Path = Assign a Folder which contains excel files for example "C:\Merge\"
FileName = Dir(Path & "*.xlsx")
'Check FileName in the Given Location
Do While FileName <> ""
'Open Excel File
Workbooks.Open FileName:=Path & FileName, ReadOnly:=True
'Copy all the sheet to this workbook
For Each Sheet In ActiveWorkbook.Sheets
Sheet.Copy After:=ThisWorkbook.Sheets(1)
Next Sheet
'Close the ActiveWorkbook
Workbooks(FileName).Close
'Assign a Excel FileName
'Assign Next Excel FileName
FileName = Dir()
Loop
'Display a Message
MsgBox "Files has been copied Successfull", , "MergeMultipleExcelFiles"
End Sub
In this post i will share the script to copy all the excel files from one folder to Single Excel File.
Below is the Script
Sub MergeMultipleWorkbooks()
'Define Variables
Dim Path, FileName As String
'Assign Values to Variables
Path = Assign a Folder which contains excel files for example "C:\Merge\"
FileName = Dir(Path & "*.xlsx")
'Check FileName in the Given Location
Do While FileName <> ""
'Open Excel File
Workbooks.Open FileName:=Path & FileName, ReadOnly:=True
'Copy all the sheet to this workbook
For Each Sheet In ActiveWorkbook.Sheets
Sheet.Copy After:=ThisWorkbook.Sheets(1)
Next Sheet
'Close the ActiveWorkbook
Workbooks(FileName).Close
'Assign a Excel FileName
'Assign Next Excel FileName
FileName = Dir()
Loop
'Display a Message
MsgBox "Files has been copied Successfull", , "MergeMultipleExcelFiles"
End Sub
See it in Action.
Hello,
ReplyDeletei did copy the script into Module and modified the Path information as explained above, though none of the documents being copied into the workbook and i just get the pop up : Files has been copied successfully. Please advise.
thank you
Same thing happened to me, but it turned out I needed to add the end backslash (\) to my path folder.
ReplyDeleteDONT WORK
ReplyDeleteHi, tried your script but keep getting an error message saying Sub or Function not defined. Please help.
ReplyDelete