+ Reply to Thread
Results 1 to 10 of 10

Thread: Append multiple workbooks with multiple worksheets

  1. #1
    Registered User
    Join Date
    08-29-2008
    Location
    Virginia
    Posts
    48

    Append multiple workbooks with multiple worksheets

    Hi,

    I would like to append multiple workbooks with multiple worksheets in a separate workbook. For eg. I have workbook "A" with sheets 1,2,3 and workbook "B" with sheets 4,5,6. Now I want to append "A" and "B" to create workbook "C" with sheets 1,2,3,4,5,6.

    Thank you in advance.

  2. #2
    Registered User
    Join Date
    08-29-2008
    Location
    Virginia
    Posts
    48
    This is just a repost to my earlier question. I realize people in this forum are very busy and don't have time to go through each and every thread. But I would be very grateful for any kind of help on this matter.

    Thanking you again.

  3. #3
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,777
    Open Workbook A and save it as Workbook C.

    With Workbook C still open, open Workbook B. Select all the sheets, and do Edit > Move or Copy Sheet, tick Make a copy, and select Workbook C from the dropdown.

  4. #4
    Registered User
    Join Date
    08-29-2008
    Location
    Virginia
    Posts
    48
    Thank you for the quick response but I wanted to write a macro. I apologize for not mentioning it in my earlier post.

  5. #5
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,777
    Actually, I should have noticed that you were in the Programming forum.

    Why don't you start by recording a macro doing it, and then we'll clean it up from there?

  6. #6
    Registered User
    Join Date
    08-29-2008
    Location
    Virginia
    Posts
    48
    I haven't done much. I need to write a code that will loop through all the worksheets in selected workbooks and export them to Masterdb.xls.

    Sub test()
    
    Dim FName As Variant
    Dim sFil   As String
        Dim sTitle As String
         Dim iFilterIndex As Integer
        
        sFil = "Excel Files (*.xls),*.xls"
        
        iFilterIndex = 1
        
        sTitle = "Select files to open"
       
    FName = Application.GetOpenFilename(sFil, iFilterIndex, sTitle, , True)
    
    
    Set NewBook = Workbooks.Add
    With NewBook
    .Title = "Master Sheet"
    .SaveAs Filename:="Masterdb.xls"
    End With
    End Sub
    Last edited by shg; 09-05-2008 at 05:43 PM.

  7. #7
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,777
    Please read the Forum Rules about Code Tags. I've edited your post to correct them.

  8. #8
    Registered User
    Join Date
    08-29-2008
    Location
    Virginia
    Posts
    48
    I'm still trying to figure it out but with no success. Any ideas??

    Sub test()
    
    
    Dim NewBook As Workbook
    Set NewBook = Workbooks.Add
    With NewBook
    .Title = "Master Sheet"
    .SaveAs Filename:="Masterdb.xls"
    End With
    
    Dim FD As FileDialog
    Dim FFS As FileDialogFilters
    
    'On Error GoTo Problem
    
    Set FD = Application.FileDialog(msoFileDialogOpen)
    
    With FD
    Set FFS = .Filters
        With FFS
        .Clear
       ' .Add ".xls"
        End With
    
    .AllowMultiSelect = True
    
    Dim IntCounter As Integer
    Dim Item
    
    IntCounter = 1
    
    For Each Item In .SelectedItems
    
    Sheets(Array(Sheets.Count - 1)).Copy after:=Sheets(Sheets.Count)
    'NewBook.Sheets.Add after:=Sheets(Sheets.Count)
    IntCounter = IntCounter + 1
    Next Item
    End With
    'End Sub
    
    'Problem:
    'MsgBox "problem"
    End Sub

  9. #9
    Forum Guru shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2007, 2010
    Posts
    25,777
    Try this:
    Sub sam10()
        Dim wkbMst  As Workbook     ' master
        Dim wkbInp  As Workbook     ' input workbook
        Dim wks     As Worksheet    ' worksheets in input workbooks
        
        Dim sFile   As String
        Dim bRept   As Boolean
        Dim nWks    As Long
        Dim iWks    As Long
    
        sFile = Application.GetSaveAsFilename(FileFilter:="Excel files, *.xls", _
                                              Title:="Master Workbook")
        If sFile = "False" Then Exit Sub
        
        Set wkbMst = Workbooks.Add
        nWks = wkbMst.Sheets.Count
        wkbMst.SaveAs sFile
        
        sFile = Application.GetOpenFilename
        Application.EnableEvents = False    ' disable macros in workbooks to be opened
        
        Do While sFile <> "False"
            Set wkbInp = Workbooks.Open(sFile)
            For Each wks In wkbInp.Worksheets
                wks.Copy After:=wkbMst.Sheets(wkbMst.Sheets.Count)
            Next wks
            
            If Not bRept Then
                ' delete the original sheets in the blank workbook
                Application.DisplayAlerts = False
                For iWks = 1 To nWks
                    wkbMst.Worksheets(1).Delete
                Next iWks
                Application.DisplayAlerts = True
                bRept = True
            End If
            
            wkbInp.Close SaveChanges:=False
            wkbMst.Save
            sFile = Application.GetOpenFilename
        Loop
        
        Application.EnableEvents = True
    End Sub

  10. #10
    Registered User
    Join Date
    08-29-2008
    Location
    Virginia
    Posts
    48
    I got it to work. Thanks Shg.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Automatically format multiple worksheets
    By Kez in forum Excel Programming
    Replies: 0
    Last Post: 08-29-2008, 08:25 AM
  2. Append multiple worksheets into single worksheet
    By steve-waters in forum Excel General
    Replies: 1
    Last Post: 01-02-2008, 05:11 AM
  3. Replies: 1
    Last Post: 11-12-2007, 09:01 AM
  4. Run Macro on Multiple Workbooks (.csv) Files at Once
    By davehunter in forum Excel Programming
    Replies: 0
    Last Post: 04-26-2007, 10:52 AM
  5. Printing different worksheets from multiple workbooks
    By andycreighton in forum Excel General
    Replies: 8
    Last Post: 01-11-2007, 07:27 AM

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.2.0