Copy an Enterprise Task Field to Assignment Text Fields in Microsoft Project
Question details
Copy the value of an enterprise custom task field into a text field on each of the task's assignments.

- Product
- Microsoft Project
- Device & OS
- not provided
- Scenario
- A Project VBA macro needs to read an enterprise task field by its friendly name and populate an assignment text field.
- Observed behavior
- The desired result is for each assignment to receive its task's enterprise field value in a field such as Text1.
Open the project containing the enterprise custom field and confirm its exact friendly name. Check that assignment Text1 is the intended destination, because the macro will overwrite its existing values.
Use VBA to copy the task field into assignment Text1
Resolve the enterprise task field name, read each task's value, and write it to the task's assignments.
Task enterprise fields can be read with GetField after resolving the friendly name to a field constant. Assignment fields use direct properties such as Text1 rather than SetField.
In Microsoft Project, open the project and press Alt+F11 to open the VBA editor. Choose Insert > Module.
Paste this code into the module. Replace "Project Cost Type" with the exact enterprise task field name if yours is different: Sub CopyTaskFieldToAssignments() Dim fieldId As Long Dim taskItem As Task Dim assignmentItem As Assignment Dim fieldValue As String fieldId = Application.FieldNameToFieldConstant("Project Cost Type", pjTask) For Each taskItem In ActiveProject.Tasks If Not taskItem Is Nothing Then fieldValue = taskItem.GetField(fieldId) For Each assignmentItem In taskItem.Assignments assignmentItem.Text1 = fieldValue Next assignmentItem End If Next taskItem End Sub
Place the cursor inside the macro and press F5. Return to Project and inspect assignment Text1 values in an assignment view, such as Task Usage, after adding the Text1 column.

Use WPS Office for Project-Related Documents and Spreadsheets
WPS Office is a free, lightweight alternative for working with familiar Office documents and spreadsheets. Its familiar interface and Microsoft Office format compatibility make it easy to move supporting project files between suites. It does not run Microsoft Project or replace this Project VBA macro.

Frequently Asked Questions
How do I refer to an enterprise field whose name contains spaces?
Use Application.FieldNameToFieldConstant with the exact friendly name and pjTask, such as FieldNameToFieldConstant("Project Cost Type", pjTask). Pass the returned ID to the task's GetField method.
Can I use SetField to update an assignment text field?
Assignment fields generally require direct properties, such as assignmentItem.Text1. SetField is used for supported task and resource fields rather than assignment fields.
What happens to tasks that have no assignments?
The loop over taskItem.Assignments has no items to process, so no assignment field is changed for that task.
Will assignment Text1 automatically appear in server reports?
Not necessarily. Check the fields exposed by your Project Server or Project Online reporting configuration and publish the project as appropriate. A local field or formula may not be available for reporting.




