none
How to create a new Custom Column in MS Project RRS feed

  • Question

  • Hi,

    I'm creating a plugin for MS Project. I have created a Project 2013 and 2016 VSTO Add-in using C#.

    Now, I want to add a custom column like how when we open a blank project you get Task Mode, Task Name, Duration... all this by default like wise i want to create one more column to be displayed by default for all the projects.

    May i know how to do that?

    Tuesday, August 30, 2016 11:58 AM

Answers

  • In MSProject, we could record the macro to check the object model. To add a custom column, I would suggest you record the macro and add the custom column manually, then you could get the code in VBE, so that you could check what object model it actually uses.

    E.g. The following adds the column of which fieldID is Text1.

    For fieldID, please visit  PjField Enumeration (Project)

                   

    Globals.ThisAddIn.Application.SelectTaskColumn(Column: "Add New Column");
                    Globals.ThisAddIn.Application.TableEditEx(Name: "&Entry", TaskTable: true, NewName: "", NewFieldName: "Text1", ShowInMenu: true);
                    Globals.ThisAddIn.Application.TableApply(Name: "&Entry");
    


    Thursday, September 1, 2016 2:29 AM
    Moderator

All replies

  •  >>want to add a custom column like how when we open a blank project you get Task Mode, Task Name, Duration... all this by default like wise i want to create one more column to be displayed by default for all the projects.

     

    Hi,

    Replace ThisAddIn_Startup with the following code, it adds two new tasks when the add-in starts up.

    For more information, please visit Walkthrough: Creating Your First VSTO Add-in for Project

            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                this.Application.NewProject += new Microsoft.Office.Interop.MSProject._EProjectApp2_NewProjectEventHandler(Application_NewProject);
            }
            void Application_NewProject(Microsoft.Office.Interop.MSProject.Project pj)
            {
                MSProject.Task newTask = pj.Tasks.Add
                    ("This text was added by using code", missing);
                newTask.Start = DateTime.Now;
                newTask.Duration = "3";
                newTask.ResourceNames = "Rob Caron, Kelly Krout";
     
                MSProject.Task anothernewTask = pj.Tasks.Add
                    ("This is the 2nd taks i added using code", missing);
                anothernewTask.Start = DateTime.Now;
                anothernewTask.Duration = "2";
                anothernewTask.ResourceNames = "celeste";
            }

    Wednesday, August 31, 2016 3:28 AM
    Moderator
  • Hi Celeste, 

    Thanks for your reply.

    I dont want to create tasks or Rows but i want to add new column called "Something" and on double click of each cell of that column a window should open with appropriate values of that task.

    Wednesday, August 31, 2016 6:53 AM
  • In MSProject, we could record the macro to check the object model. To add a custom column, I would suggest you record the macro and add the custom column manually, then you could get the code in VBE, so that you could check what object model it actually uses.

    E.g. The following adds the column of which fieldID is Text1.

    For fieldID, please visit  PjField Enumeration (Project)

                   

    Globals.ThisAddIn.Application.SelectTaskColumn(Column: "Add New Column");
                    Globals.ThisAddIn.Application.TableEditEx(Name: "&Entry", TaskTable: true, NewName: "", NewFieldName: "Text1", ShowInMenu: true);
                    Globals.ThisAddIn.Application.TableApply(Name: "&Entry");
    


    Thursday, September 1, 2016 2:29 AM
    Moderator
  • Thanks Celeste, that solves the problem

    Srini

    Wednesday, September 7, 2016 10:43 AM