+ Reply to Thread
Results 1 to 3 of 3

Excel 2007 : Macro copy sheet into diff workbook

  1. #1
    Registered User
    Join Date
    04-29-2009
    Location
    nashville
    MS-Off Ver
    Excel 2007
    Posts
    6

    Macro copy sheet into diff workbook

    Hello all, I am trying to create a macro to copy a sheet from a closed excel file into the currently open workbook that I will be running the macro from. I have tried several bits of code that seemed to work for others but not me, figured it was because I was using 2007. the last bit of code I tried was:

    Please Login or Register  to view this content.
    I got the runtime error 9, subscript out of range error on this bit...I thought this should be a simple macro but am having trouble with it. Any suggestions?? Thanks in advance for your help guys!!
    Last edited by VBA Noob; 04-29-2009 at 05:09 PM. Reason: Added code tags as per forum rules

  2. #2
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Macro copy sheet into diff workbook

    hi

    AFAIK, the use of "workbooks(..." requires the file to be part of the collection of currently open workbooks. I would suggest opening the file first (you can make it hidden as well, or re-close it immediately).

    You may be interested in Dave McRitchie's code:
    http://www.ozgrid.com/VBA/ExtractFromClosedWorkbook.htm

    hth
    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Macro copy sheet into diff workbook

    As Rob says, Workbooks() always refers to an open workbook, and never includes a path.
    Entia non sunt multiplicanda sine necessitate

+ 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