Results 1 to 3 of 3

Inconsistent error with Sheets.Copy

Threaded View

  1. #1
    Registered User
    Join Date
    10-29-2008
    Location
    Earth
    Posts
    14

    Inconsistent error with Sheets.Copy

    I have a suite of spreadsheets. All material code is in a file called Control.xls, with EnableEvents false and calculation manual. Another file (referred to internally as wbTCR) contains detailed reports. A third (wbRpt) is being assembled from the detailed and summary reports. The summary report comes from a fourth file (wbNew). This contains a SAP BW query, and the file is repeatedly opened, the query refreshed with different parameters, the report copied and the file closed. It is at the point where the report is copied that I have a problem. The line copying the report is:

    wbNew.Sheets("Summary").Copy after:=wbRpt.Sheets(wbRpt.Sheets.Count)

    The number of sheets in each assembly changes depending on the number of children that each parent has, and this changes from month to month. Last month, the code worked perfectly. This month, I sometimes get an error on this line. The error occurs on the ninth, tenth or eleventh child, i.e. when the number of sheets is 19, 21 or 23. It is possible that some parents with more than 10 children have run without problems. The error is:

    Error 1004 - Copy method of Worksheet class failed

    I have inserted the following two lines before the problem line, and they work around the problem:

    wbNew.Sheets("Summary").Copy
    Workbooks(Workbooks.Count).Close

    There is no conflict in sheet names. The crash occurs at the same point for a given parent, but I can see no reason why the point should change from one parent to another. Indeed, I can see no reason why the line should stop working, having worked last month and having worked for the first 8 or more calls this time.

    Has anyone seen anything like this? If so, can you give me any clues?

    Regards,

    John Davies
    Last edited by JDavies; 03-02-2010 at 07:58 AM.

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