« Happy New Year | Main | 5 Good Reasons to use Earned Value and 5 Reasons not to »

Setting Microsoft Project Level Custom fields using VBA

I was recently trying to set a number of different project level custom fields using VBA and got tired of finding and editing all the parameters so I wrote a small wrapper function that you may find useful:

Private Function setPField(ByVal field As String, ByVal newValue As String, ByRef proj As Project)
pfield = FieldNameToFieldConstant(field, pjProject)
proj.ProjectSummaryTask.SetField FieldID:=pfield, value:=newValue
End Function

It does two things. First it converts the field name into the field constant. This way you can supply the name of the field. Then it uses that field and sets the text value. It might not seem like much but it does make it easier for me to reuse this function, than having to search through a longer statement and find out what I need to set. To use it just supply the field name, the value and the project like this:

setPField field:="My Custom Field", newValue:="foo", proj:=ActiveProject
  • Iterating through Microsoft Project Subprojects
  • Microsoft Project Undo Levels and Macros
  • VBA to VSTO Tutorial Part Two - Adding a Command Bar and Buttons
  • VBA and Visual Basic For ... to ... statements
  • Office VBA for Mac After 2008
  • Analyze Microsoft Project Resource Usage Data In Excel
  • VBA Writing to a text file (MS Project, Excel)
  • MS Project VBA - Trim Function
  • Using a ComboBox in a Microsoft Project Userform
  • Telling Time - ProjDateDiff, VB DateDiff and Application.DateDifference

  • About

    The previous article is Happy New Year.

    The next article is 5 Good Reasons to use Earned Value and 5 Reasons not to.

    Current articles are in the main index page and you can find a complete list of articles in the archives.

    Creative Commons License
    This weblog is licensed under a Creative Commons License.
    Powered by
    Movable Type 3.34