+ Reply to Thread
Results 1 to 3 of 3

Automatically importing sheets from one workbook to another

Hybrid View

  1. #1
    Registered User
    Join Date
    01-10-2010
    Location
    Arlington VA
    MS-Off Ver
    Excel 2003
    Posts
    7

    Automatically importing sheets from one workbook to another

    I have a program that outputs data into an Excel spreadsheet (we'll call it Workbook 1) that has 17 worksheets. The format of the sheets is always the same but the number of rows of data entries varies.

    Then I have another Excel file (Workbook 2) that has 2 sheets of calculations on it. Is there a way to show Workbook 2 the file path of Workbook 1 and have it add the 17 worksheets after the existing 2 worksheets? I don't need Workbook 2 to continuously update as changes are made to Workbook 1, it would just have to happen once.

    Thanks in advance for your help.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Automatically importing sheets from one workbook to another

    hugedomer11,

    You should be able to use the following macro to accomplish what you're looking for:
    Sub ImportSheetsMacro_for_hugedomer11()
        
        Static wbDataPath As String: wbDataPath = Application.GetOpenFilename("Excel Files, *.xls*")
        If wbDataPath = "False" Then Exit Sub
        Application.ScreenUpdating = False
        
        Static wbDest As Workbook: Set wbDest = ActiveWorkbook
        Static wbData As Workbook: Set wbData = Workbooks.Open(wbDataPath)
        
        Dim ws As Worksheet
        For Each ws In wbData.Sheets
            ws.Copy After:=wbDest.Sheets(wbDest.Sheets.Count)
        Next ws
        wbData.Close False
        Application.ScreenUpdating = True
        
    End Sub


    Hope that helps,
    ~tigeravatar

  3. #3
    Registered User
    Join Date
    01-10-2010
    Location
    Arlington VA
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Automatically importing sheets from one workbook to another

    @tigeravatar

    Thanks for the help! This is exactly what I was looking for. It worked the first time with no problems.

+ 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