+ Reply to Thread
Results 1 to 16 of 16

Debug error help: Method 'Copy' of Object '_Worksheet' failed

  1. #1
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    459

    Debug error help: Method 'Copy' of Object '_Worksheet' failed

    crosslink here: http://www.mrexcel.com/forum/excel-q...et-failed.html

    Hi all,

    I'm having an odd issue with my below macro.

    The macro copies a tab from a current file and then does some manipulation then save's it to a specified folder.
    (note: some non relevant code has been omitted to keep it short)

    The code works great if i run it over and over but once i have opened the file which has been saved and then close it and try rerun the macro i get the debug error on red portion of the code "Method 'Copy' of Object '_Worksheet' failed"

    Anyway i can prevent this from happening?

    Please Login or Register  to view this content.
    Last edited by Gti182; 03-26-2014 at 06:20 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: Debug error help: Method 'Copy' of Object '_Worksheet' failed

    Hello,

    I havent tried to run the code but is it a s simple as moving the "offending statement" down one line until it is after the Set wb1 statement. It looks like you dont have focus on the "Sheet1" so possibly the order is wrong or you need to actually open the workbook that you are trying to copy from??

    Just a few random, rapid thoughts

    Cheers

    Jmac1947

    1. Please consider clicking on the * Add Reputation if you think this post has helped you
    2. Mark your thread as SOLVED when question is resolved

  3. #3
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    459

    Re: Debug error help: Method 'Copy' of Object '_Worksheet' failed

    my code is most likely full of errors as i'm a bit of an amateur.

    If I move the offending code down one line it then sets the master file as wb1. This then causes the master file containing the macro to close and leaves the file i created open which is the opposite of what i'm trying to achieve

  4. #4
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    459

    Re: Debug error help: Method 'Copy' of Object '_Worksheet' failed

    would it perhaps be better just to copy the worksheet and physically paste it into a new file then set that file as wb1?

  5. #5
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: Debug error help: Method 'Copy' of Object '_Worksheet' failed

    put your macro in a file ran it closed it opened it re-ran it all works fine for me. is sheet1 having its name changed at some point? try changing it to
    Please Login or Register  to view this content.
    Sub Reputation()
    Dim Problem as Variant
    Dim Reputation as Integer
    For Each Problem in Forum.Threads
        If Problem.Title = "*[Solved]*" and Solver.Name = "Leon V (AW)" Then Reputation = Reputation + 1
    Next Problem
    End Sub

  6. #6
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    459

    Re: Debug error help: Method 'Copy' of Object '_Worksheet' failed

    my actual sheet name is "Project Master" not "Sheet1" as per the code, does that make a difference?

    Please Login or Register  to view this content.
    the sheet it's copying is Sheet number 2. I've changed the code to below to test but having the same error this way
    Please Login or Register  to view this content.
    Last edited by Gti182; 03-26-2014 at 06:49 AM.

  7. #7
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: Debug error help: Method 'Copy' of Object '_Worksheet' failed

    side note your spath ends in a \ and your save code ads a \ so your save location is currently Z:\Template\\Test.xlsx which fails.

    if the macro is referencing Sheets("Project Master") and the sheet is called Project Master it should work.
    what do you get if you put in
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    459

    Re: Debug error help: Method 'Copy' of Object '_Worksheet' failed

    well spotted on the savepath, i forgot to remove the "\" after template in the above code. the actual filepath is much longer and doesn't include the erroneous "\".

    If i run your above code message box says "Project Master" without inverted commas

    I've noticed when i get the error my master file is open but there is also a new book open which is an exact copy of my whole master file including all tabs/macro buttons etc. not just the tab i'm trying to copy which i'd expect from the code.
    Last edited by Gti182; 03-26-2014 at 06:58 AM.

  9. #9
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    459

    Re: Debug error help: Method 'Copy' of Object '_Worksheet' failed

    hmm this is odd. I've tried running my above pasted code in post 1 in a new test file and it doesn't give the error.

    I've included my actual code below without any omissions, perhaps that flags up something

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: Debug error help: Method 'Copy' of Object '_Worksheet' failed

    try adding in
    Please Login or Register  to view this content.
    at the start and using
    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    459

    Re: Debug error help: Method 'Copy' of Object '_Worksheet' failed

    code works fine but still having the error after opening and closing the newly created file and rerunning the macro.

    I don't get the error if i open and close the newly created file and then close and reopen the master file and rerun the macro.

    Is it something to do with the copy function storing the worksheet in memory?

  12. #12
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: Debug error help: Method 'Copy' of Object '_Worksheet' failed

    is the master file an old .xls file?

  13. #13
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    459

    Re: Debug error help: Method 'Copy' of Object '_Worksheet' failed

    .xlsm

    could there be a problem with my save fileformat?

  14. #14
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: Debug error help: Method 'Copy' of Object '_Worksheet' failed

    no not if it is .xlsm.
    I can't recreat this to test it.
    I run macro it copies sheet 2 and saves the copy as test.xlsx and closes it.
    I open test.xlsx then close it
    I run macro it copies sheet 2......etc (here is where you can't copy sheet 2 but you can get the name of sheet 2).

    I can't think of any reason why it would not be able to copy a sheet it can see is there (and we know it can see it as you put in sheet(2).name in just befor copy and it was fine).

  15. #15
    Forum Contributor
    Join Date
    10-04-2010
    Location
    London
    MS-Off Ver
    Office 365
    Posts
    459

    Re: Debug error help: Method 'Copy' of Object '_Worksheet' failed

    it is quite odd.

    I just noticed that I dont get the error if i run the macro then open and close test.xlsx then save the master file before rerunning the macro?

    This is the exact error i get:
    Run-time error '-21474178848 (80010108)':
    Method 'Copy' of object '_Worsheet' failed

  16. #16
    Registered User
    Join Date
    07-08-2008
    Location
    South Africa
    MS-Off Ver
    Office 2010
    Posts
    8

    Re: Debug error help: Method 'Copy' of Object '_Worksheet' failed

    Hi Gti182
    Did you ever sort this out? I'm using Excel 2010 and getting the same error!
    Thanks,
    Bruce

+ 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. [SOLVED] Runtime Error '1004' Method 'Range' of object '_Worksheet' failed
    By ovalstar in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-20-2013, 02:15 PM
  2. [SOLVED] Help! Error 1004, method 'Range' of object'_Worksheet' failed.
    By zac_595 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-07-2013, 02:55 PM
  3. Run time Error 1004 Method 'Range' object '_Worksheet 'failed
    By Monica1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-24-2013, 07:42 AM
  4. me too - run-time error '1004' method 'range' of object '_worksheet' failed
    By ASAFSWIS in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-07-2013, 05:14 PM
  5. Help! Method 'Range' of object '_Worksheet' failed (msg) error
    By jasono in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-17-2011, 12:44 PM

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