Copying Multiple Sheets Via Macro Fails After X Copies

  • Hi,


    I have some code in an excel macro which is copying numerous worksheets and I am trying to overcome the classic "Run-Time Error 1004: Copy method of worksheet class failed"


    If I could save my Workbook, Close, Reopen and continue from where I leftoff in the code then I believe that would solve the problem but I am not sure if this is possible.


    Any help would be greatly appreciated as I have been searching forums for a couple of days now and feel like I am going round in circles.

  • Re: Save Close Reopen Workbook & Continue Running Code


    Hi


    welcome to the forum.


    that is possible, although it does not seem to achieve a great deal, I think it might be more profitable to attempt to discover why the macro is giving an error, perhaps you could post the code that you have and maybe someone can spot the problem


    Robert


    ADDED BY ADMIN


    [GS="Copy Method of Worksheet Class failed"]*[/GS]

  • Re: Save Close Reopen Workbook & Continue Running Code


    Hi gavk,


    Welcome to Ozgrid.


    I think you'll need to


    i) not assume the solution to the problem, i.e. your thread title describe what you want to achieve. This will prevent you from getting the best response (and I think Dave's on the warpath today from another post doing the same thing!! :-)))


    ii) post the part of your code which is failing, including any relevant contextual code.


    Hope that gets you some good help.

  • Re: Save Close Reopen Workbook & Continue Running Code


    Thanks for your replies
    Appologies, I did read the rules regarding titles and thought that my title would be better than "Copy Method of Worksheet Class failed"


    The problem I am having is described here
    http://support.microsoft.com/kb/210684


    I have posted the microsoft resolution below because it is easier to discuss than posting my own code:


    This resolution does not work for me because my workbook path is stored as a variable (rather than just enetering the path name ("c:\test2.xls") as above). When i close my workbook I am unable to reopen because the path name which is stored as a variable is lost.

  • Re: Save Close Reopen Workbook & Continue Running Code


    This is a bug in Excel; there's a KB article that you'll find on MSDN if you search for the error message. A solution is to close and reopen the workbook, but then you need the code that does it to run in a different workbook.


    As an alternative, you could insert a worksheet from a template, rather than copying an existing sheet. Or insert a new sheet and copy formatting and content from the other sheet.

    [SIZE=1]Entia non sunt multiplicanda sine necessitate.[/SIZE]

  • Re: Save Close Reopen Workbook & Continue Running Code


    Shg, Thanks for your reply.


    Isn't the kb article you refer to the one i have linked to in my last post?


    I am unable to close and reopen my workbook as you suggest because my code always stops working when the original file closes, please see example below


  • Re: Save Close Reopen Workbook & Continue Running Code


    Quote

    Isn't the kb article you refer to the one i have linked to in my last post?


    Yes, it is. I didn't notice.

    Quote

    I am unable to close and reopen my workbook as you suggest because my code always stops working when the original file closes


    As I said,

    Quote

    ... you need the code that does it to run in a different workbook.

    [SIZE=1]Entia non sunt multiplicanda sine necessitate.[/SIZE]

  • Re: Save Close Reopen Workbook & Continue Running Code


    Quote from shg

    ......you need the code that does it to run in a different workbook.


    In the last example I gave I have saved a copy of the original file as "temp.xls", opened "temp.xls" and then run the sub called SaveTemp (within "temp.xls"). Since "temp.xls" is a different workbook i thought that would be sufficient?


    Do you think there might be some changes I can make so that SaveTemp keeps running after the original workbook (SpecFile) closes?


    Thanks again

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!