none
Customize and show hidden columns in MS Project using C# RRS feed

  • Question

  • Hello,

    I'm exporting information from my winforms .NET application to a new MS Project file. I'm sending some information to the Text1, Text2, etc columns, but this columns are hidden by default in the Gantt diagram. I'm trying to find a way to customize the column  title, and show this columns by default when the customer exports info from my app to a project file and he opens it. It's possible to do that programmatically??

    As additional information, I'm working with Microsoft.Office.Interop.MSProject.

    Thanks for your help.

    Kind regards.


    Jose Alberto Marti

    Friday, December 9, 2016 11:35 AM

Answers

  • Yes. Easiest way to find solution is to record a macro in Project of you doing just what you want. That gives you the VBA code that you can then translate into C#.

    Rod Gill
    Author of the one and only Project VBA Book and VBA developer.
    www.project-systems.co.nz

    Sunday, December 18, 2016 7:44 PM
    Moderator
  • Those are application properties. Check for pApp's properties and methods.
    Wednesday, December 21, 2016 4:56 PM
  • Hi,

    Here is the code that solve the problem to help other people:

    'Declare the application variable
    pApp = New MSProject.Application()
    'Method to show a column
    pApp.TableEditEx("&Entrada", True, NewFieldName:="Texto1", Width:=15, ShowInMenu:=True, LockFirstColumn:=True, RowHeight:=1, ColumnPosition:=8)
    pApp.TableApply("&Entrada")
    'Change the column name
    pApp.CustomFieldRename(MSProject.PjCustomField.pjCustomTaskText1, "Empresa")
    pApp.TableApply("&Entrada")

    "&Entrada" is the name of the table, the best way to know it is, as Rod said, record a macro and review the vba code.

    Thanks for your help!!


    Jose Alberto Marti


    Thursday, December 22, 2016 8:20 AM

All replies

  • Yes. Easiest way to find solution is to record a macro in Project of you doing just what you want. That gives you the VBA code that you can then translate into C#.

    Rod Gill
    Author of the one and only Project VBA Book and VBA developer.
    www.project-systems.co.nz

    Sunday, December 18, 2016 7:44 PM
    Moderator
  • Hi Jose,

    Yes, you can write VBA macros and deploy across all project professional clients in your company/network. So that, as and when user opens the project professional, the macro loads and executes accordingly. But, the main disadvantage with this approach is you should your IT support team to push your macro changes to all project professional clients. If you are not satisfied with this answer, please provide more details about your issue, I am happy to share my knowledge.

    Regards,

    Vamsi


    vamsi

    Tuesday, December 20, 2016 4:28 PM
  • Hi,

    First of all, thanks for your replies. I'll try to give you more details about my problem. I tried to use the solution given by Rod, but I can't find the properties in .NET that the vba code returned to me. I'll show you:

    Sub Macro1()
    ' Macro Macro1
    ' Macro grabada el mié 21/12/16 por Jose Alberto Martí Martín.
        TableEditEx Name:="&Entrada", TaskTable:=True, NewName:="", NewFieldName:="Texto1", Width:=20, ShowInMenu:=True, LockFirstColumn:=True, DateFormat:=255, RowHeight:=1, ColumnPosition:=9
        TableApply Name:="&Entrada"
        SelectTaskColumn Column:="Texto1"
        SelectTaskColumn Column:="Texto1"
        CustomFieldRename FieldID:=pjCustomTaskText1, NewName:="Empresa"
        TableApply Name:="&Entrada"
        SelectTaskField Row:=1, Column:="Texto1"
    End Sub

    This is the code that Project gave me when I recorded a Macro showing the Text1 column and after changing the header text "Text1" with "Empresa".

    My problem is, as I said before, that I can't find the correct properties in my .NET objects to do the substitution of the header text and the posible "Visible = True".

    I'm working with this objects:

    pApp = New MSProject.Application()
    '-----
    Dim pProjectRes As MSProject.Project = pApp.ActiveProject
    '---------
    Dim t As MSProject.Task

    My code is in VB.NET, but if you are more comfortable in C#, I understand it in the same way.

    I hope that my explanation could be understandable. 

    Thanks for your help.

    Regards,


    Jose Alberto Marti

    Wednesday, December 21, 2016 4:49 PM
  • Those are application properties. Check for pApp's properties and methods.
    Wednesday, December 21, 2016 4:56 PM
  • To be sure your code works every time, I would create a new table you apply each time. Always recreate the table each time, that way you know what columns are visible.

    I would even create a new View for the table and train users to revert to the Gantt chart after reviewing your data.


    Rod Gill
    Author of the one and only Project VBA Book and VBA developer.
    www.project-systems.co.nz

    Thursday, December 22, 2016 5:44 AM
    Moderator
  • Hi,

    Here is the code that solve the problem to help other people:

    'Declare the application variable
    pApp = New MSProject.Application()
    'Method to show a column
    pApp.TableEditEx("&Entrada", True, NewFieldName:="Texto1", Width:=15, ShowInMenu:=True, LockFirstColumn:=True, RowHeight:=1, ColumnPosition:=8)
    pApp.TableApply("&Entrada")
    'Change the column name
    pApp.CustomFieldRename(MSProject.PjCustomField.pjCustomTaskText1, "Empresa")
    pApp.TableApply("&Entrada")

    "&Entrada" is the name of the table, the best way to know it is, as Rod said, record a macro and review the vba code.

    Thanks for your help!!


    Jose Alberto Marti


    Thursday, December 22, 2016 8:20 AM