none
How to clone a task RRS feed

  • Question

  • Dear experts,

     

    I want to copy a complete "x.mpp" into another "clone.mpp", by iterating over all tasks in this way:

    foreach (Task myTaskOld in myPrj.Tasks)

    {

        Task myTaskNew = mrPrjClone.Tasks.Add();

       ==> but how can I get the content of myTaskOld now in myTaskNew ??

    }

     

    Thank you in advance


    • Edited by Somigur Wednesday, September 28, 2011 9:57 PM
    Wednesday, September 28, 2011 9:53 PM

All replies

  • Shortest code is copy tehn paste whole tasks, otherwise you need to copy all information, EG Name then Duration then links then resources then assignments etc.

    Would be quicker to copy the file then delete what you don't want from hte copy. A further file, save as will minimize file size after the deletes.


    Rod Gill

    The one and only Project VBA Book Rod Gill Project Management
    Wednesday, September 28, 2011 11:53 PM
    Moderator
  • Hi Rod,

    ok, I was not precise enough. So here some additional information.

    1.

    I'm aware of the "copy-file-then-it-shrinks"-Method. But it still has a lot of superfluous content stored

    2.

    Of course, I not only want to copy, but I have some "filtering/manipulation" in between the "foreach"

    3. I tried your approach:

     

    .......app is loaded before
    Project prjOld = app.ActiveProject;
    
    
    Application appClone = new Application(); 
    Project prjClone = appClone.ActiveProject;
     foreach (Task task in prjOld.Tasks) { 
    Task taskNew = prjClone.Tasks.Add();
    taskNew = task; ??????????????
    }


    I have an issue with this:

    taskNew = task; increments continuously prjOld.Tasks.Count. So effectively I have an endless-loop.

    How can I copy one task to the other?

    • Edited by Somigur Thursday, September 29, 2011 5:37 PM
    Thursday, September 29, 2011 6:41 AM