Share via

MS Project macro question

Anonymous
2019-08-19T14:29:29+00:00

Hi,

I am trying to use a macro to create a custom status field, using the text2 field.  I tried using the record function which produced this code:

Sub Macro1()

' Macro Macro1

    SelectTaskColumn Column:="Task Mode"

    TableEditEx Name:="&Entry", TaskTable:=False, NewName:="", NewFieldName:="Text2", Width:=9, ShowInMenu:=True, LockFirstColumn:=True, DateFormat:=255, RowHeight:=1, ColumnPosition:=1

    TableApply Name:="&Entry"

    TableEditEx Name:="&Entry", TaskTable:=False, NewName:="", FieldName:="Text2", NewFieldName:="Text2", Title:="", ColumnPosition:=1

    TableApply Name:="&Entry"

   SelectTaskField Row:=1, Column:="Text2"

End Sub

When I recorded the macro, the desired new field was produced.  However, when I try to run the code as a macro within a new project, it errors on

SelectTaskField Row:=1, Column:="Text2"

Run-time error '1101': The argument value is not valid

I have a second macro, which will be combined once I get over this error, that renames the field and assigns G-Y-R indicators.  

The reason I am using a macro is that multiple people will be using adding the status to their reports.

Any assistance is appreciated!

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2019-08-19T17:00:24+00:00

    John,

    Thanks for the reply and explanation. 

    I am attempting to insert a column in the first position.  The column will be for a R-Y-G indicator for the task or phase.  I have the code in a macro for the indicator, I can not figure out how to insert a column via a macro.

    Was this answer helpful?

    0 comments No comments
  2. John Project 49,710 Reputation points Volunteer Moderator
    2019-08-19T15:18:20+00:00

    RedMan_567,

    Recorded macros operate on the active view (foreground processing). When you recorded the macro your view showed the Text2 field. When you opened a new project, the Text2 field was likely not displayed as a column, hence the run-time error.

    For reference, macros written to operate directly on Project objects, (e.g. tasks, resources, assignments, etc.), the code is independent of the view and normally faster, particularly with larger files. If you can tell us more about what exactly you want to do with the Text2 field, we can help you write more efficient code.

    Hope this helps.

    John

    Was this answer helpful?

    0 comments No comments