Results 1 to 3 of 3

Thread: EXCEL combining workbooks ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2002
    Location
    Here and There
    Posts
    92

    EXCEL combining workbooks ?

    Can someone plz help me with this problem.
    assume first of all that i open excel with a blank workbook (ie book1.)
    my next step is to open (say?) three other workbooks. so,at this stage i have 4 open (shown in the window menu option after clicking it)

    what i literally want to do is to run vba code once so that it iterates through the workbook collection (not including personal.xls if present) moving each of the 2nd, 3rd and 4th workbooks active sheet to book1.



    thanks in advance
    Gaz
    ab uno disce omnes

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: EXCEL combining workbooks ?

    should be easy to do

    workbooks.open filename
    to open each file, then you have to choose which sheet you want to move (or copy?)
    select the range within the sheet and put its copy its vaues to a loctation on the correct sheet in book1, close that work book and do the same again for the next ones

    how do you know which sheet you want to move data from? all the data?
    how do you know where you want to position the data in book1?

    pete

  3. #3
    Frenzied Member
    Join Date
    May 2004
    Location
    Carlisle, PA
    Posts
    1,045

    Re: EXCEL combining workbooks ?

    Gaz:
    ===

    This might give you something to play with. I threw it together in about 5 minutes. IT IS NOT TESTED ... IT IS ONLY A ROUGH GUESS AT WHAT YOU NEED. As pete said, it is not difficult once you understand the basics.
    Code:
    Option Explicit
    Sub Macro1()
    '
    'Create an identifier for the Collector Workbook
    Dim collector_book As Workbook
    'ID for the Workbook Iterator
    Dim abook As Workbook
    
    'Create the Collector workbook
    Set collector_book = New Workbook
    
    'Iterate through all open workbooks collecting sheets
    For Each abook In Workbooks
        'Don't regress into the Collector Book!
        If abook <> collector_book Then
            'Activate each book
            abook.Activate
            'Copy the sheet
            ActiveSheet.Copy After:=collector_book.Sheets(xlLast)
        End If
    Next
    
    'SaveAs the Collector
    collector_book.SaveAs FileName:="C:\Test\JUNK-Collector.xls", FileFormat:= _
        xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
        , CreateBackup:=False
    
    End Sub
    Good Luck and Good Learning!
    Blessings in abundance,
    All the Best,
    & ENJOY!

    Art . . . . Carlisle, PA . . USA

Posting Permissions

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



Click Here to Expand Forum to Full Width