Search code examples
vbams-project

Adding "Successors" columns using VBA


How do I set an additional column in MS Project?

I tried the record macro option and copy-pasted the code but still facing errors.

Sub addcolumn()
' Macro addcolumn
    SelectTaskColumn Column:="Add New Column"
    TableEditEx Name:="&Entry", TaskTable:=False, NewName:="", FieldName:="Text1", NewFieldName:="Successors", Title:="", ColumnPosition:=8
    TableApply Name:="&Entry"
End Sub

Receive this error:

Run-time error '1004':
The field "Successors" does not exist.


Solution

  • Since Successors is a Task field, the second argument needs to be True:

    TableEditEx Name:="&Entry", TaskTable:=True, NewName:="", FieldName:="Text1", NewFieldName:="Successors", Title:="", ColumnPosition:=8
    

    See Application.TableEditEx method for more details.