Microsoft Office Forums

  • Search forums
  • Newsgroup Archive
  • Project Newsgroups
  • Project Developer

adding tasks, resources and assignments to a project using VBA

  • Thread starter Mark VII
  • Start date May 3, 2007
  • May 3, 2007

Greetings -- I'm working up a program to take a Excel list of tasks and resources and bring it into Project. (We have a standard estimating Excel template that is currently entered into Project manually, and am trying to automate this.) Am having trouble assigning resources to tasks. Here's a high level of how the code looks. dim tsk as Task dim rst as Resource dim asn as Assignment dim proj as Project set proj as Application.Projects.Add For each row on the input spreadsheet set tsk = proj.tasks.add tsk.Name = < task name from spreadsheet > '* this goes OK proj.Resources.Add (< resource name from spreadsheet > ) '* this goes OK lngResourceId = RetreiveResouceId(name) '* function to find resource and get its id '* trouble starts here Set asn = tsk.Assignments.Add(tsk.ID, lngResourceId, <units from spreadsheet>) asn.Work = < hours from spreadsheet > next input row Creating the task records goes OK. So does adding the resource and retrieving the resulting ID. Where it gets messy is creating the resource assignments. The "Set asn = tsk.Assingment...." gives 1101, The Argument Value is not Valid if I retrieve the units value from the spreadsheet (even if it's 1). However, the statement works OK if I hard code the units value to 1. If I run with units hard coded to 1, and reach the "asn.Work = < value from spreadsheet >" line, I get the 1101 error again. Have searched high and low for an example of the correct way to specify these values and come up dry. Does anyone have any suggestions? Thanks a million. Mark  

Mark VII said: Greetings -- I'm working up a program to take a Excel list of tasks and resources and bring it into Project. (We have a standard estimating Excel template that is currently entered into Project manually, and am trying to automate this.) Am having trouble assigning resources to tasks. Here's a high level of how the code looks. dim tsk as Task dim rst as Resource dim asn as Assignment dim proj as Project set proj as Application.Projects.Add For each row on the input spreadsheet set tsk = proj.tasks.add tsk.Name = < task name from spreadsheet > '* this goes OK proj.Resources.Add (< resource name from spreadsheet > ) '* this goes OK lngResourceId = RetreiveResouceId(name) '* function to find resource and get its id '* trouble starts here Set asn = tsk.Assignments.Add(tsk.ID, lngResourceId, <units from spreadsheet>) asn.Work = < hours from spreadsheet > next input row Creating the task records goes OK. So does adding the resource and retrieving the resulting ID. Where it gets messy is creating the resource assignments. The "Set asn = tsk.Assingment...." gives 1101, The Argument Value is not Valid if I retrieve the units value from the spreadsheet (even if it's 1). However, the statement works OK if I hard code the units value to 1. If I run with units hard coded to 1, and reach the "asn.Work = < value from spreadsheet >" line, I get the 1101 error again. Have searched high and low for an example of the correct way to specify these values and come up dry. Does anyone have any suggestions? Thanks a million. Mark Click to expand...
John said: My first guess is that the units value in Excel is of the wrong data type, like maybe a text value. < Click to expand...
  • May 4, 2007
Mark VII said: Hi John -- Good point. If I assign the contents of the relevant spreadsheet cell to a variable, then assign the variable to the Work property, it works. Go figure. Have run into a new problem, though. As I loop through the resources and populate their work values, numbers start changing strangely. For example, I assign resource1 to the task and let Units default to 100%. Then, I set his Work property to specify his hours. So far so good. (At this point, the task Work = resource1's work.) Then, I assign resource2 to the task, let his units default to 100%. Still OK. When I set resource2's work hours, I would expect project to set resource2's hours to the specified value, leave resource1's hours alone, and set the task work hours to the sum of resource1 and resource2's hours. Instead, project reduces resource1's work hours. Also, the task total work hours is a value lower than expected. Any thoughts here? Thanks, Mark Click to expand...
John said: The "numbers" are probably changing because of the default task type. < Click to expand...
  • May 5, 2007
Mark VII said: I think that was it. I changed my code, and though not exactly as expected, the hours allocations for multiple resources per task are now much closer. Thanks a million for helping me get this program on line. It's going to save us a TON of time. Mark Click to expand...

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Similar Threads

0
0
1
0
0
0
0
0
  > >
Go to Page...
  09-28-2010, 12:40 PM
 
CGM3
  10-05-2010, 05:51 AM
 
Thread Tools
Display Modes
Similar Threads
Thread Thread Starter Forum Replies Last Post
DaveSmith Word 0 08-24-2010 06:44 PM
ccmystery Outlook 0 04-09-2010 05:59 AM
alharris Word 0 11-16-2009 12:00 AM
Moiraes Fate Office 0 05-18-2007 12:22 PM
isapaine Misc 0 01-11-2006 07:51 AM
- -

Carl Sprake

  • Walking Kit
  • Walking Resources
  • Oxfordshire Way
  • Oxford Greenbelt Way
  • Project 2013
  • Project Server
  • Project 2007 and PWA
  • Project 2010

Using VBA To Check Task and Assignment Fields

I’m currently working on a project to create a macro for MS Project. The intention is that this macro will  fire either on Save or on the click of a button and will check to see if certain fields have been filled out for tasks and assignments. Any missing fields will be reported back to the user.

We use Project Server to generate a “Daily Log” where we can record work against tasks that have been assigned to us. In order to make the completion of the daily log as easy as possible for the end users and for the plan owner (not to mention our finance department), we want to be able to check that most of the required information is in place in the first place.

Task fields

It is relatively easy to loop through tasks and check for task level fields.

The easiest thing to do is to work with all the tasks in the current collection of tasks in the active project.

First we need to check that the task is actually a valid task (i.e. not a blank row) and that it is not a summary task.

Then we can populate a number of variables with the required values.

Here we can see that VBA has a way for us to get the value of task fields.

Assignment Fields

Reading assignment level custom field values is a bit more tricky. If the name of the custom field is one word (i.e. there are no spaces), then according to various other web sites I have looked at, for an assignment a; “a.fieldname” will do the trick. Unfortunately, if the field name does contain spaces then this method will not work.

Since I was unable to resolve the issue by working in the background I decided I had to work in the foreground (i.e. by working with a view).

To make sure that I covered all the task and could work with all the required fields I wanted to do the following:

  • Use a Enterprise view
  • Remove any filters
  • Display all tasks

This can be achieved using the following code:

We can now loop through all the rows in the view. This is one area where I have used a bit of a hack. I haven’t found an easy way to count the number of used rows in the current view. However, I can count the number of tasks in the current project and I know that we rarely assign more than one person to a task, so the following should give me a high enough limit to count to.

The view I’m using is a Task Usage view and therefore contains the names of tasks as well as the resources assigned to those tasks. What I need to do is to differentiate between Tasks and Assignments.

Now I can use the SelectTaskField to select a specific cell in row r and column specified by a field name.

SelectTaskField

A couple of important points about this command:

  • Column – this should be the real name of the column as stored in Project, not the name shown in the view. Hence the use of Column:=”Name”, rather than Column:=”Task Name”
  • RowRelative – the default value for this is True and will therefore select a cell r rows down from the currently active cell. Therefore, this should be set to False to ensure that it is always row r that is used.

Having selected the cell in the “Name” column of row r we can read the text in the cell using:

It is also possible to query the name of the task associated with the currently active cell.

And we can therefore compare sTest1 with sTest2. If they are the same then we are looking at a Task. However, if they are different then we are looking at a resource assigned to a task and the current row is an assignment. We can therefore pick up cell values from other columns in the row and compare them to expected values.

Final Outline

So, the final outline of the code looks like this:

Share this:

  • No comments yet.
  • July 31, 2012 at 13:11 Using VBA To Check Task and Assignment Fields « Joined Up Solutions

Leave a comment Cancel reply

Recent posts.

  • SW Coast Path
  • Oxfordshire Way Circular Walk Route 8
  • A Day For Photography
  • Plant Identification
  • Oxfordshire Way Circular Walk Route 7
  • Gordale Scar and Malham Cove
  • Climbing Shoes Insane Pain vs Comfort
  • Countif and Countifs
  • Microsoft Office Specialist–First step
  • Shotover Atlas Project Survey 20150326
  • 2013 Fundraiser
  • General Musings and Rants
  • Medieval Re-enactment
  • Photography
  • Documentation
  • Suggest Ideas
  • Support Forum
  • WordPress Blog
  • WordPress Planet
  • February 2015
  • January 2015
  • December 2014
  • November 2014
  • September 2014
  • August 2014
  • December 2013
  • October 2013
  • September 2013
  • August 2013
  • January 2013
  • December 2012
  • September 2012
  • August 2012
  • January 2012
  • December 2011
  • November 2011
  • October 2011
  • September 2011
  • August 2011
  • February 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • February 2009
  • January 2009
  • December 2008
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • February 2008
  • January 2008

' src=

  • Already have a WordPress.com account? Log in now.
  • Subscribe Subscribed
  • Copy shortlink
  • Report this content
  • View post in Reader
  • Manage subscriptions
  • Collapse this bar

ms project vba assignment

Assignment fields

The following are the assignment fields in Microsoft Office Project. For more information, click a field name.

Actual Cost fields

Actual Finish fields

Actual Overtime Cost fields

Actual Overtime Work fields

Actual Start fields

Actual Work fields

ACWP fields

Assignment Delay fields

Assignment Units fields

Baseline Cost fields

Baseline Finish fields

Baseline Start fields

Baseline Work fields

Baseline1-10 Cost fields

Baseline1-10 Finish fields

Baseline1-10 Start fields

Baseline1-10 Work fields

BCWP fields

BCWS fields

Confirmed fields

Cost fields

Cost Rate Table fields

Cost Variance fields

Cost1-10 fields

Critical fields

Date1-10 fields

Duration1-10 fields

Enterprise Cost1-10 fields

Enterprise Date1-30 fields

Enterprise Duration1-10 fields

Enterprise Flag1-20 fields

Enterprise Number1-40 fields

Enterprise Resource Outline Code1-29 fields

Enterprise Text1-40 fields

Finish (assignment field)

Finish Variance fields

Finish1-10 fields

Flag1-20 fields

Hyperlink fields

Hyperlink Address fields

Hyperlink Href fields

Hyperlink SubAddress fields

Indicators fields

Leveling Delay fields

Linked Fields fields

Notes fields

Number1-20 fields

Outline Level fields

Overallocated fields

Overtime Cost fields

Overtime Work fields

Peak fields

Percent (%) Work Complete fields

Priority fields

Project fields

Regular Work fields

Remaining Cost fields

Remaining Overtime Cost fields

Remaining Overtime Work fields

Remaining Work fields

Request/Demand (assignment field)

Resource Group fields

Resource ID (assignment field)

Resource Initials fields

Resource Name (assignment field)

Resource Type (assignment field)

Response Pending fields

Start fields

Start Variance fields

Start1-10 fields

Task ID (assignment field)

Task Name (assignment field)

Task Outline Number (assignment field)

Task Summary Name fields

TeamStatus Pending fields

Text1-30 fields

Unique ID fields

Update Needed fields

Work fields

Work Contour fields

Work Variance fields

Facebook

Need more help?

Want more options.

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

ms project vba assignment

Microsoft 365 subscription benefits

ms project vba assignment

Microsoft 365 training

ms project vba assignment

Microsoft security

ms project vba assignment

Accessibility center

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

ms project vba assignment

Ask the Microsoft Community

ms project vba assignment

Microsoft Tech Community

ms project vba assignment

Windows Insiders

Microsoft 365 Insiders

Was this information helpful?

Thank you for your feedback.

  • Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers
  • Advertising & Talent Reach devs & technologists worldwide about your product, service or employer brand
  • OverflowAI GenAI features for Teams
  • OverflowAPI Train & fine-tune LLMs
  • Labs The future of collective knowledge sharing
  • About the company Visit the blog

Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Get early access and see previews of new features.

Reading and writing MS Project TimeScaleData for Resources, and Assignments

I am pulling projected cost into Excel reports and an external db. Part of the monthly projections are to update the project overheads. So I need to accurately pull monthly cost as well as write monthly cost to the overheads tasks.

I am having trouble understanding why would you read and write to an Assignment instead of directly to the cost Resource?

Read the month cost by resource (simplified):

There is only one TimeScaleValue in tsvs (the single month) so I believe that I'm fine just referencing tsvs(1).Value instead of having to increment through the collection.

Read month cost with assignments:

And finally write the month overhead cost to the overhead task:

This method works for me but I am frustrated I cannot get it to work writing directly to the resource cost. I don't really understand why I would have to read or write to an assignment (either task or resource) instead of directly to the resource itself. Could anyone explain why one should read and write costs using assignments or if there is a better way using the resources directly?

Thanks for your time.

Martijn Pieters's user avatar

The answer is that the assignments table contains the TimeScaleData that relates the resource to the task (and vice versa), so you must write to the assignment related to the resource (or task). Resource TimeScaleData is really the related Assignment TimeScaleData of the resource.

Your Answer

Reminder: Answers generated by artificial intelligence tools are not allowed on Stack Overflow. Learn more

Sign up or log in

Post as a guest.

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy .

Not the answer you're looking for? Browse other questions tagged vba ms-project or ask your own question .

  • The Overflow Blog
  • The hidden cost of speed
  • The creator of Jenkins discusses CI/CD and balancing business with open source
  • Featured on Meta
  • Announcing a change to the data-dump process
  • Bringing clarity to status tag usage on meta sites
  • What does a new user need in a homepage experience on Stack Overflow?
  • Feedback requested: How do you use tag hover descriptions for curating and do...
  • Staging Ground Reviewer Motivation

Hot Network Questions

  • Question about word (relationship between language and thought)
  • Advanced Composite Solar Sail (ACS3) Orbit
  • Filtering polygons by name in one column of QGIS Attribute Table
  • Beatles reference in parody story from the 1980s
  • How to clean a female disconnect connector
  • The head of a screw is missing on one side of the spigot outdoor
  • Do you believe something to be the truth or do you know the truth?
  • lib/xorg/Xorg →lib/x86_64-linux-gnu/libc.so →xorg/modules/drivers/nvidia_drv.so causes a segmentation fault. Should I report that to Debian team?
  • Can ago be used with since?
  • What was the typical amount of disk storage for a mainframe installation in the 1980s?
  • How long should a wooden construct burn (and continue to take damage) until it burns out (and stops doing damage)
  • How does a miner create multiple outputs in a coinbase transaction?
  • Circuit that turns two LEDs off/on depending on switch
  • Are fuel efficiency charts available for mainstream engines?
  • Starting with 2014 "+" signs and 2015 "−" signs, you delete signs until one remains. What’s left?
  • What are the most common types of FOD (Foreign Object Debris)?
  • Setting the desired kernel in GRUB menu
  • What happens on a CAN bus when impedance is too low?
  • Plausible orbit to have a visible object slowly circle over the night sky
  • How high does the ocean tide rise every 90 minutes due to the gravitational pull of the space station?
  • Where did they get facehuggers from?
  • Is reading sheet music difficult?
  • Looking for the name of a possibly fictional science fiction TV show
  • Why does the guardian who admits guilt pay more than when his guilt is established by witnesses?

ms project vba assignment

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Resource.SetField method (Project)

  • 7 contributors

Sets the value of the specified resource custom field.

expression . SetField ( _FieldID_ , _Value_ )

expression A variable that represents a Resource object.

Name Required/Optional Data type Description
Required For a local custom field, can be one of the constants for resource custom fields. For an enterprise custom field, use the method to get the FieldID.
Required The value of the field.

The following example shows how to access an enterprise resource custom field by using the SetField method and the GetField method for the Resource object together with the FieldNameToFieldConstant and FieldConstantToFieldName methods.

To use the example, use Project Web App to create an enterprise resource text custom field named, for example, TestEntResText .

Restart Project Professional with a Project Server profile, so that it includes the new custom field.

Create a project, build the team from enterprise resources, and then assign a resource to the first task.

The TestEnterpriseResourceCF macro uses the FieldNameToFieldConstant method to find the resourceField number, for example, 205553667.

The macro shows the number and text value in a message box, by using the GetField method.

The macro sets a new value for the custom field, by using the SetField method.

The macro gets the field name by using the FieldConstantToFieldName method, and then shows the field name and new value in another message box.

For an example that uses a local resource custom field, see the GetField method.

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.

Was this page helpful?

Additional resources

IMAGES

  1. Automation Interface: Microsoft Project VBA Examples

    ms project vba assignment

  2. Microsoft Project VBA

    ms project vba assignment

  3. What is a VBA Project? (And How to Edit)

    ms project vba assignment

  4. Exploring VBA: Microsoft Project’s Macro Language

    ms project vba assignment

  5. Microsoft Project VBA

    ms project vba assignment

  6. Microsoft Project VBA

    ms project vba assignment

VIDEO

  1. Secrets to Scoring High Marks in Your IGNOU MA Economics Project mecp 101 project kaise banayen

  2. Thinking about memory in VBA

  3. Get Started With Data Entry Userforms #shortsvideo #vba #automation

  4. Формирование портфеля проектов в MS Project Pro

  5. Ler dados no MS-Project com VBA

  6. C# Beginner 3

COMMENTS

  1. Assignments object (Project)

    Use the Assignments property to return an Assignments collection. The following example displays all the resources assigned to the specified task. For Each A In ActiveProject.Tasks(1).Assignments. MsgBox A.ResourceName. Next A. Use the Add method to add an Assignment object to the Assignments collection.

  2. Assignments.Add method (Project)

    Variant. The number of resource units, expressed as a decimal or percentage, to assign to the task. The default value is 1 or 100%, depending on whether the Show assignment units as a setting is Decimal or Percentage, on the Schedule tab of the Project Options dialog box. If the maximum number of units is less than 1 (or the maximum percentage ...

  3. How to get the value of a cell in VBA MS Project

    To get the values of a task, use the Task object. In this case you'll want to loop through all of the tasks using the Tasks object (collection of all tasks). It is unclear what task fields you need, but this should get you started:

  4. adding tasks, resources and assignments to a project using VBA

    dim rst as Resource. dim asn as Assignment. dim proj as Project. set proj as Application.Projects.Add. For each row on the input spreadsheet. set tsk = proj.tasks.add. tsk.Name = < task name from spreadsheet > '* this goes OK. proj.Resources.Add (< resource name from spreadsheet > ) '* this goes OK.

  5. Resource.Assignments property (Project)

    In this article. Gets an Assignments collection representing the assignments for the resource. Read-only Assignments.. Syntax. expression.Assignments. expression A variable that represents a Resource object.. Support and feedback. Have questions or feedback about Office VBA or this documentation?

  6. MS Project VBA Assignment Add Method

    If you want to change an existing assignment, you first must delete the assignment and then use the add method. Or, if you just want to change the units assignment of an existing assignment, the following syntax will work. ActiveProject.Tasks (1).Assignments (1).Units=0.6. Note: you would need a loop of all that tasks assignments to determine ...

  7. MS Project VBA

    MS Project VBA - Add Assignment in Consolidated file Is there ANY way to add an Assignment from a macro within a consolidated Project file? I have multiple files consolidated/checked out and want to change a Resource Assignment for a specific Task. The Assignments.Add method seems to require a Task ID.

  8. MS Project VBA

    Little bit of faulty thinking by Microsoft on Project 2007 I think. Basically, in a one task, one resource one assignment schedule, ActiveProject.Tasks(1).Assignments(1).Text1 is a different custom field from ActiveProject.Resources(1).Assignments(1).Text1. Some people use VBA to copy the same value across so at least they have the same values.

  9. Setting an Assignment Field from VBA

    The setup is this: a Cost1 column has been added to the Task view, the value of which is calculated by VBA code in the project's Calculate event and then assigned to the field: Code: Private Sub Project_Calculate(ByValpj As Project) Dim tskT As Task Dim asnA As Assignment 100 For Each tskT In ActiveProject.Tasks 110 If Not (tskT Is Nothing ...

  10. Assignment.Owner property (Project)

    Gets or sets the name of the assignment owner. Read/write String. Syntax. expression. Owner. expression A variable that represents an Assignment object. Support and feedback. Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and ...

  11. Using VBA To Check Task and Assignment Fields

    Using VBA To Check Task and Assignment Fields. I'm currently working on a project to create a macro for MS Project. The intention is that this macro will fire either on Save or on the click of a button and will check to see if certain fields have been filled out for tasks and assignments. Any missing fields will be reported back to the user.

  12. Application.ResourceAssignment method (Project)

    The names of the resources to be assigned, removed, or replaced in the selected tasks. Note Project will not assign a resource if thousands separators or decimal separators are included in the unit values. Operation. Optional. Long. If Operation is omitted, Project assigns the resources to the selected tasks. The default value is pjAssign.

  13. Importing multiple resource assignments and hours worked to tasks from

    Assigning resources manually per task is time consuming. Not every resource is assigned to each task, and each resource has varying hours within a task. Example- task 1 may have R1 30 hours, R2 10 hours, R3 5 hours, with the resources working concurrently, for no more than the highest number of hours assigned for this task, (30 hours). Task 2 ...

  14. vba

    Assignment.Resource.GetField(FieldNameToFieldConstant("Billing Rate")) But getting error: <The argument is not valid.> How do I access this field at the assignment level? On a related note, the field can be accessed in PowerBI under Assignment table at "BillingRate_T", but unable to access in Project VBA Macro. Thank you in advance!

  15. Assignment fields

    The following are the assignment fields in Microsoft Office Project. For more information, click a field name. Actual Cost fields. Actual Finish fields. Actual Overtime Cost fields. Actual Overtime Work fields. Actual Start fields. Actual Work fields. ACWP fields.

  16. Assignments.Count property (Project)

    RID = R.ID. Exit For End If Next R. If RID <> 0 Then ' Assign the resource to tasks without any resources. For Each T In ActiveProject.Tasks. If T.Assignments.Count = 0 Then. T.Assignments.Add ResourceID:=RID. End If Next T. Else. MsgBox Prompt:=RName & " is not a resource in this project.", buttons:=vbExclamation.

  17. vba

    The answer is that the assignments table contains the TimeScaleData that relates the resource to the task (and vice versa), so you must write to the assignment related to the resource (or task). Resource TimeScaleData is really the related Assignment TimeScaleData of the resource.

  18. MS Project 2016 VBA Assignment UniqueID not matching screen

    The difference in the two values is a power of 2, 2 to the 20th to be exact (i.e. 2^20). Knowing that value, you can introduce a "fudge factor" when reading the assignment unique ID with VBA. Another approach is to copy the Assignment Unique ID to a number field (e.g. Number1). If you use VBA to read the number field, it will show the correct ...

  19. Resource.SetField method (Project)

    Create a project, build the team from enterprise resources, and then assign a resource to the first task. The TestEnterpriseResourceCF macro uses the FieldNameToFieldConstant method to find the resourceField number, for example, 205553667. The macro shows the number and text value in a message box, by using the GetField method.