Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Copy excel Sheet from one workbook to anoter

Posted on 2012-09-07
Medium Priority
Last Modified: 2012-09-07
My destination workbook is C:\ExcelReport\SEE_REPORT_201296_dest.xlsx
and I want to get the worksheet "SEE Report2_source" from workbook C:\ExcelReport\SEE_REPORT_201296_source.xlsx

 Sub MergeSheets(ByVal x As Integer)
        Dim SrcBook As Excel.Workbook
        Dim fso As Object, f As Object, ff As Object, f1 As Object

        objExcel = New Excel.ApplicationClass
        objExcel.ScreenUpdating = False
        fso = CreateObject("Scripting.FileSystemObject")
        f = fso.Getfolder("C:\ExcelReport\")
        ff = f.Files
        objRange = objWorksheet.UsedRange
        For Each f1 In ff
            'objExcel = New Excel.ApplicationClass
            objWorkbook = objExcel.Workbooks.Open("C:\ExcelReport\SEE_REPORT_201296_dest")
            objExcel.Visible = True
            ' SrcBook = objExcel.Excel.Workbooks.Open("C:\ExcelReport\SEE_REPORT_201296.xlsx")
            objRange.Range("A1:IV" & objRange.Range("A65536").End(Excel.XlDirection.xlUp).Row).Copy()
            ' objWorkbook.ThisWorkbook.Worksheets(1).Activate()
            objRange.Range("A65536").End(Excel.XlDirection.xlUp).Offset(1, 0).PasteSpecial()
            objExcel.Application.CutCopyMode = False

    End Sub

Open in new window

Question by:mikensu12
  • 2
LVL 36

Expert Comment

ID: 38376654
If you had references to the 2 workbooks you should just be able to do this.

  objWorkbook = objExcel.Workbooks.Open("C:\ExcelReport\SEE_REPORT_201296_dest")
  srcWorkbook = objExcel.Workbooks.Open("C:\ExcelReport\SEE_REPORT_201296_source.xlsx")

  srcWorkbook.Worksheets("SEE Report2_source").Copy (objWorkbook.Worksheets(1))

Open in new window

LVL 36

Accepted Solution

Norie earned 2000 total points
ID: 38376815
Thought I'd add this which copies the sheet after the last sheet in the destination workbook.
        srcWorkbook.Worksheets("SEE Report2_source").Copy(After:=dstWorkbook.Worksheets(dstWorkbook.Worksheets.Count))

Open in new window


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question