PDA

View Full Version : [SOLVED] need help with combine files



elmnas
03-13-2015, 06:11 AM
Hi guys,


I know there is loads script that combine workbooks


my problem is I don't how to make one I found fit my conditions.




I got two files


C:/test/1/myFile1.xls
the file contains one sheet (sheet1)




C:/test/1/MyFile2.xls
the file contains one sheet (sheet2)




I need a script that take/copy sheet 2 from "MyFile2.xls"
into myFile1.xls after the first sheet then save and overwrite the existing file.


I got like 100 files in the folder so it need to specify the script take from "MyFile2.xls"


Could someone help me with this code?


Thank you in advance.

jonh
03-13-2015, 08:23 AM
Sub test()
CopySheets Workbooks.Open("C:\test\1\myFile1.xls"), Workbooks.Open("C:\test\1\MyFile2.xls")
End Sub

Public Sub CopySheets(src As Workbook, dst As Workbook)
Dim sht As Worksheet
For Each sht In src.Worksheets
sht.Copy After:=dst.Sheets(dst.Sheets.Count)
Next
dst.Close True
src.Close False
End Sub

elmnas
03-13-2015, 09:18 AM
thank you already solved tho.