none
Cannot programmatically select a task in Team planner - Office MS Project 2010 RRS feed

  • Question


  • Hi,

    I'm using Visual Studio 2010 32 bits, MS Project 32 bits on a windows 7 64 bits environment.
    I created a MS project 2010 addin in Visual Studio. I can do many things with this addin, add ribbon, create tasks,
    change colors in gant view...
    However I cannot selected a task in the team planner view !
    I use SelectTPTask in the application instance as referenced (http://msdn.microsoft.com/en-us/library/ms474284.aspx).
    After this selection I want to change the color of the task by using SegmentFillColor method but nothing happens.
    If I manually click on a task then SegmentFillColor works and the task color is changed.
    Here is the code of the action:
    private void buttonPriority_Click(object sender, RibbonControlEventArgs e)
    		{
    			var app = Globals.ThisAddIn.Application;
    			var pj = app.ActiveProject;
     
    			//create Tasks
     
    			Task newTask = pj.Tasks.Add("First task");
    			newTask.Duration = "3";
    			newTask.ResourceNames = "Resource A";
     
    			newTask = pj.Tasks.Add("Second task");
    			newTask.Duration = "4";
    			newTask.ResourceNames = "Resource B";
     
    			//Change color of the assignments
     
    			foreach (Task t in app.ActiveProject.Tasks)
    			{
    				if ((t != null) && !(bool)t.Summary)
    				{
    					bool b1 = app.SelectTPTask(t.UniqueID);
    					bool b2 = app.SelectTaskAssns();
    					bool b3 = app.SegmentFillColor(0xFFFFFF);
    				}
    			}
    		}
    
    
    
    Is it a bug or I do not use it properly,
    Thanks,
    Alex.




    • Moved by Cindy Meister MVP Sunday, July 25, 2010 5:03 PM Project, not VSTO-related (From:Visual Studio Tools for Office)
    • Moved by Jim Corbin Monday, July 26, 2010 2:47 PM A Project programming question (From:Project Standard and Professional General Questions and Answers)
    Saturday, July 24, 2010 3:35 PM

Answers

  • Hi Alex,

    First, before you use Team Planner methods, you should change to the Team Planner view: ViewApplyEx("Team Planner"). However, there appears to be a bug in the SelectTPTask method. In VBA, if you record a macro and select an assignment in the Team Planner, the macro does not show the SelectTPTask step. If you use, for example, Application.SelectTPTask(1) in a macro or in the Immediate window in the VBE, Project hangs and then restarts. I've notified the product team about this.

    Thanks for raising the issue.

    --Jim

    • Marked as answer by Jim Corbin Monday, July 26, 2010 4:55 PM
    Monday, July 26, 2010 4:53 PM

All replies

  • Hi Alex,

    First, before you use Team Planner methods, you should change to the Team Planner view: ViewApplyEx("Team Planner"). However, there appears to be a bug in the SelectTPTask method. In VBA, if you record a macro and select an assignment in the Team Planner, the macro does not show the SelectTPTask step. If you use, for example, Application.SelectTPTask(1) in a macro or in the Immediate window in the VBE, Project hangs and then restarts. I've notified the product team about this.

    Thanks for raising the issue.

    --Jim

    • Marked as answer by Jim Corbin Monday, July 26, 2010 4:55 PM
    Monday, July 26, 2010 4:53 PM
  • Hi Jim,

    I am trying to achieve something similar in VBA macro.

    I am calling Application.SelectTPTask which is returning true and then setting the color with SegmentFillColor.

    But the color is not being set.

    Any idea when this issue will be resolved.

    I also have another situation where I have a master project with subprojects.

    As my subproject task do not get listed under Application.ActiveProject.Tasks how can I select them using the SelectTPTask method.

    Regards

    Adrian

    Monday, August 9, 2010 2:18 AM
  • Hello,

    Well, I am very angry at Microsoft because, 2 years on, the bug is still there, and no one seems to care about this.

    Every time I have to deal with VBA stuff, it's always the shittiest time of my life.

    Thanks MS

    • Proposed as answer by Quentin V Tuesday, February 5, 2013 5:29 PM
    Wednesday, November 28, 2012 3:21 PM
  • Working solution (MS Proj 2013) for similar task is:

    Sub ChangeTaskColorBasedOnCondition()

        Application.ViewApply Name:="Team Planner"

          

        For Each task In ActiveProject.Tasks

       

            Application.SelectTPTask (task.UniqueID)

            Application.SelectTaskAssns

       

            If (InStr(task.Name, "t")) Then

                SegmentFillColor Color:=192

            Else

                SegmentFillColor Color:=0

            End If

           

            Application.SelectTPTask

           

        Next

       

    End Sub

    Thursday, September 11, 2014 1:14 PM
  • Working solution (MS Proj 2013) for similar task is:

    Sub ChangeTaskColorBasedOnCondition()

        Application.ViewApply Name:="Team Planner"

          

        For Each task In ActiveProject.Tasks

       

            Application.SelectTPTask (task.UniqueID)

            Application.SelectTaskAssns

       

            If (InStr(task.Name, "t")) Then

                SegmentFillColor Color:=192

            Else

                SegmentFillColor Color:=0

            End If

           

            Application.SelectTPTask

           

        Next

       

    End Sub

    Hello,

    this Script works very well with Single Projects.

    How would the code be written, if I have only sub-projects in the file?

    Thanks for all Ideas! Maik

    Monday, January 11, 2016 3:53 PM
  • Maikowy,

    I tried it by modifying the above code to address the subproject tasks and it didn't work. I believe it is due to the unique way the UniqueID field is created for a master project with subprojects and how that may or may not apply to an active view. I tried using the unique ID of the task at subproject level and I also tried using the unique ID of the subproject task as identified in the master, and both generate a run time error.

    Maybe someone else has a trick, but my guess is you can't do this with VBA on a master project.

    John

    Monday, January 11, 2016 4:53 PM
  • Hi All. 

    I know this is an old thread but for anyone interested in applying styles to subprojects tasks in Team Planner (also in Proj2016), the above implementation works, but Subprojects need to be expanded at least one time in Gantt View before cycling on Tasks; if not, Subprojects Tasks be not catched by ForEach Task loop.

    You can expand entire Project and Subprojects through a:   

    Application.OutlineShowTasks(Microsoft.Office.Interop.MSProject.PJTaskOutlineShowLevel.pjTaskOutlineShowLevelMax)


    Paolaj1



    • Edited by Paolaj Monday, June 25, 2018 3:45 PM
    Monday, June 25, 2018 3:38 PM