Reading Assignment Enterprise Custom Field Values with VBA

Hello,

There has been a number of people asking how to read assignment enterprise custom field values with VBA. In fact, we ran into this issue internally with our dogfood efforts and fixed it in SP1. So, if you need to get/set assignment custom field values, the first step is to download SP1:

https://www.microsoft.com/downloads/details.aspx?FamilyID=cec3e1e2-d802-4a03-bc78-05c48472559b&displaylang=en

Once you have SP1 installed, it is fairly easy to read assignment enterprise custom fields. When you read and set task and resource enterprise custom fields, you use the GetField and SetField methods in VBA. To read and set the assignment values you don't use the GetField and SetField, but instead use the name of the enterprise custom field as a property of the assignment.  There are a couple of caveats, however:

  • The field name can't contain spaces in the name
  • When you're writing your code, you won't get auto complete to show you the field name. This is because the property isn't a part of the type library and therefore isn't early bound.  As long as you pass in a valid field name, however, then the code will late bind to it. 

Here is a short example. Suppose your custom Field name is "ecfName", here is how you would read it:

For Each T in ActiveProject.Tasks

  If Not (T is Nothing) Then

    For Each A in T.Assignments

      assignCFVal = A.ecfName

    Next A

  End If

Next T

Chris Boyd