Consulting

Results 1 to 3 of 3

Thread: need help with combine files

  1. #1
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    114
    Location

    need help with combine files

    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.

  2. #2
    VBAX Expert
    Joined
    Oct 2012
    Posts
    726
    Location
    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

  3. #3
    VBAX Contributor
    Joined
    Jun 2014
    Posts
    114
    Location
    thank you already solved tho.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •