+ Reply to Thread
Results 1 to 5 of 5

Find, Merge and create a new workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    10-14-2009
    Location
    Bristol,England
    MS-Off Ver
    Excel 2007
    Posts
    22

    Find, Merge and create a new workbook

    I have looked around, and while i can find half of a solution i can't find a complete one and hope someone can help.

    every week i create from crystal reports a series of reports for each of four areas, these are split into two because of the data that is required, so i have two halfs of a whole.

    What i want to do is this:

    Afetr exporting the files, Loop through a folder on my network

    1. Open up the two similar named files Area1 - 1.xls, Area1 - 2.xls and merge the files together.

    2.Save this new file in a predetermined folder with a new name Area1 - 1&2combined.xls

    3.Close the files and move them into a 'Done' folder

    As i said, i can find some code for merging the files, but these all seem to merge into the open workbook, what i want to do is run this from a form with just a click button to merge the files.

    Hope this makes some form of sense.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Find, Merge and create a new workbook

    How does this work for you:

    Public Sub jeffwest2()
    
    Dim Area1Path As String
    Dim Area2Path As String
    Dim DonePath As String
    
    Area1Path = "" 'Put the path of Area1 - 1.xls between the quotes. Example C:\Program Files\
    Area2Path = "" 'Put the path of Area1 - 2.xls between the quotes. Example C:\Program Files\
    DonePath = "" 'Put the path of the Done folder here. Example C:\Program Files\Done\
    
    Workbooks.Open Area1Path & "Area1 - 1.xls"
    Workbooks.Open Area2Path & "Area1 - 2.xls"
    
    For a = 1 To Worksheets.Count
        ActiveWorkbook.Worksheets(1).Copy After:=Workbooks("Area1 - 1.xls").Worksheets(1)
        Workbooks("Area1 - 2.xls").Activate
    Next a
    
    Workbooks("Area1 - 1.xls").Activate
    ActiveWorkbook.SaveAs DonePath & "Area1 - 1&2combined.xls"
    
    Workbooks("Area1 - 1&2combined.xls").Close savechanges = False
    Workbooks("Area1 - 2.xls").Close savechanges = False
    
    End Sub
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Registered User
    Join Date
    10-14-2009
    Location
    Bristol,England
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Find, Merge and create a new workbook

    Thanks for the code, just one quick question, the code adds them to two different sheets, how would i change this so they are added just to one sheet?

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Find, Merge and create a new workbook

    I don't understand the question, the makes a workbook with all the sheets from both Area1 - 1.xls and Area1 - 2.xls. Are you wanting the all the sheets to be merged onto one sheet?

  5. #5
    Registered User
    Join Date
    10-14-2009
    Location
    Bristol,England
    MS-Off Ver
    Excel 2007
    Posts
    22

    Re: Find, Merge and create a new workbook

    Yes, sorry if i did not make that very clear.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1