views:

123

answers:

2

In my workbook, I copy the current sheet to keep as a record of a sale. Eventually, the workbook fills up with sales and at some point throws an error when I try to copy another sheet. After saving, then completely exiting Excel, then reloading the file, I can continue without problems. I'm guessing it's a memory issue, but I'm not quite sure how to solve it without restarting Excel. I can't remember the wording of the error exactly, but it went along the lines of "Copy method of worksheet failed". FWIW I use "Application.CutCopyMode = False" at the end of the macro that copies the sheet.

1st edit:
I'd like to post all of the code, but there's just so much of it (mostly not related to updating values, input verification, etc. etc.); if I post everything, I'd have to post all of the other functions for it to make sense. Suffice it to say, here's what I think is applicable:

ActiveSheet.Copy After:=Sheets(3)
...(more code)...
Call resetInterface(True, True, (wasScreenUpdating), (wasProtected))

and for the "resetInterface" function:

' Final operations for a typical function/sub '
Function resetInterface(Optional calc As Boolean = False, Optional ccmode As Boolean = False, Optional scrUpdate As Boolean = True, Optional protectWS As Boolean = False)
    With Application
        If calc Then
            .Calculation = xlCalculationAutomatic
            .Calculate
        End If
        If ccmode Then .CutCopyMode = False
        .ScreenUpdating = scrUpdate
    End With
    If protectWS Then ActiveSheet.Protect
End Function
A: 

The error you're referring to is: Excel VB run-time error 1004: "Copy method of Worksheet class Failed"

Can you post the macro you've written?

Dolph
+1  A: 

There used to be a problem when copying sheets in Excel that the CodeName property of the Worksheet object would be appended with a 1 and get to be too long. I think it's been fixed, but it would depend on what version you're using.

Open the VBA (Alt+F11) and show the Project Explorer (Ctl+R). Look at the CodeNames of your copied sheets. Are they Sheet1, Sheet2, etc..? Or are they Sheet1, Sheet11, Sheet111, etc...? If the latter, this may be causing the problem. See http://support.microsoft.com/kb/177634

Or it could be that you have a workbook level name, see http://support.microsoft.com/?kbid=210684

Dick Kusleika
I am using Excel 2003, and I didn't see any "Sheet1111"'s. Looks like the ms support article describes what's happening. Crappy workaround though :|
JakeTheSnake
Agree about the workaround. I was a little surprised that a fix hasn't been released. Glad you got it sorted anyway.
Dick Kusleika