+ Reply to Thread
Results 1 to 2 of 2

Copying Sheet - subscript out of range error

  1. #1
    GSP@DCS
    Guest

    Copying Sheet - subscript out of range error

    I tried to use this command
    Sheets("Report").Copy Before:=Workbooks(xl_file).Sheets(1)
    where xl_file is an object containing the full path to the file I want to
    copy the sheet into.

    When I ran this I got 'data type mismatch' so I defined xl_file_fmt as a
    string which made this statement;

    Sheets("Report").Copy Before:=Workbooks(xl_file_fmt).Sheets(1)

    Now I'm getting a 'subscrit out of range' error.....

    ARGHH.... don't know if I'll ever get this stuff.

    I'm sure someone out there can tell me the problem that I'm obviously
    overlooking

    tia
    Steve



  2. #2
    Dave Peterson
    Guest

    Re: Copying Sheet - subscript out of range error

    workbooks(xxxx)
    expects just the name--no drive, no path.

    like:

    dim xl_file as string
    xl_file = "book1.xls"
    Sheets("Report").Copy Before:=Workbooks(xl_file).Sheets(1)

    And that receiving file has to be open.

    "GSP@DCS" wrote:
    >
    > I tried to use this command
    > Sheets("Report").Copy Before:=Workbooks(xl_file).Sheets(1)
    > where xl_file is an object containing the full path to the file I want to
    > copy the sheet into.
    >
    > When I ran this I got 'data type mismatch' so I defined xl_file_fmt as a
    > string which made this statement;
    >
    > Sheets("Report").Copy Before:=Workbooks(xl_file_fmt).Sheets(1)
    >
    > Now I'm getting a 'subscrit out of range' error.....
    >
    > ARGHH.... don't know if I'll ever get this stuff.
    >
    > I'm sure someone out there can tell me the problem that I'm obviously
    > overlooking
    >
    > tia
    > Steve


    --

    Dave Peterson

+ 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