question about accessing work from vba

G

greg

Hello,

I am confused on how Project calculates work.

i create 2 tasks. Adding them both 20 hrs of work. Not duration.



Task1 has 2 resources. Each at 100%

Task2 has 1 resource at 100%.



Now I perform:

task1TotalWork = MSProject.ActiveProject.Tasks(1).Work
task1WorkResource1 = MSProject.ActiveProject.Tasks(1).Resources(1).Work
task1WorkResource2 = MSProject.ActiveProject.Tasks(1).Resources(2).Work
task2TotalWork = MSProject.ActiveProject.Tasks(2).Work
task2WorkResource1 = MSProject.ActiveProject.Tasks(2).Resources(1).Work

After running
task1TotalWork = 1200
task1WorkResource1 = 1800
task1WorkResource2 = 600
task2TotalWork = 1200
task2WorkResource1 = 1800

the only ones that make sense are the 1200. (20 hrs * 60)
and maybe the 600. 2 users. 1200 / 2
but why is it calculating the others the way they are?


thanks
 
J

JackD

You should be working with assignments, not resources.
The value for Resources(1) is all the work that that resource is performing
on all tasks
Assignments are specific to a single task and a single resource.
 
G

greg

thanks for the response.
so if i wanted to parse the tasks, and get the work for each resource in
each task, how would i do that?
i thought i could go through each task and ask the work for each resource.
MSProject.ActiveProject.Tasks<number>.Resources<number>.Work

thanks
 
J

JackD

Sub resourcework()
For Each Task In ActiveProject.Tasks
For Each Assignment In Task.Assignments
MsgBox Assignment.ResourceName _
& " " _
& Assignment.TaskName _
& " " _
& Assignment.Work
Next Assignment
Next Task
End Sub
 
G

greg

thanks. i'll give it a try

JackD said:
Sub resourcework()
For Each Task In ActiveProject.Tasks
For Each Assignment In Task.Assignments
MsgBox Assignment.ResourceName _
& " " _
& Assignment.TaskName _
& " " _
& Assignment.Work
Next Assignment
Next Task
End Sub

--
-Jack ... For project information and macro examples visit
http://masamiki.com/project

.
 

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.

Ask a Question

Top