+ Reply to Thread
Results 1 to 2 of 2

Copy worksheet from one Workbook to another

  1. #1
    Registered User
    Join Date
    12-29-2011
    Location
    San Diego, Ca.
    MS-Off Ver
    Excel 2007
    Posts
    60

    Unhappy Copy worksheet from one Workbook to another

    This seems to simple I feel dumb to not be able to figure it out.

    I have an open workbook (call it Final) with 2 WS. I want to open a second WB, called File1 and copy its only worksheet as the first WS in the WB Final. I have tried the code below and get an error 424 (object required) for the line SET WBDest. I can't figure out how to correct it. Also, is the last line in the code what I need to paste the WS as the 1st WS in Final?

    The reason Fpath and Fname are separate is that Fname will change each week. The particular name will come from User input.

    #Sub get_files()

    ' This procedure opens the workbook ("File1"), copies its only worksheet ("CG Sht") and pastes it as the 1st
    ' Worksheet into the Workbook ("Final") which contains 2 worksheets. Final is already open.

    Dim WBSource As Workbook
    Dim WBDest As Workbook
    Dim Sht_To_Copy As Worksheet
    Dim FilePath As String
    Dim FileName As String

    ' setup Destination WB
    FilePath = "C:\users\myname\documents\" 'set path to correct folder
    FileName = "final"
    Set WBDest = FPath & FName & ".xlsm"

    ' Open source workbook, select sheet and copy it.
    Set WBSource = Workbooks.Open("C:\users\myname\documents\File1.xlsm")
    WBSource.Sheets("cg Sht").Copy
    Workbooks(WBDest).Activate

    ' Now paste it as the 1st worksheet
    ActiveSheet.Paste

    End Sub#
    Last edited by gototcm; 01-23-2014 at 11:42 AM. Reason: typo

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Copy worksheet from one Workbook to another

    Why aren't you using Workbooks.Open for the destination workbook?

    PS Can you add code tags?
    If posting code please use code tags, see here.

+ 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. Copy a worksheet from one file to another
    By tstroh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-27-2013, 02:05 PM
  2. [SOLVED] Copy worksheet from one file to another
    By MissaLissa in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-16-2013, 05:00 PM
  3. [SOLVED] Copy Worksheet from another file
    By Steve in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-05-2006, 12:30 PM
  4. Copy File into Worksheet
    By Session101 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-29-2006, 10:25 AM
  5. How do I copy a worksheet from a workbook as csv file
    By Husker87 in forum Excel General
    Replies: 6
    Last Post: 03-26-2005, 06:06 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.6.0 RC 1