Share via

VBA Change assignment units

Anonymous
2015-08-10T12:29:48+00:00

Hello,

I would like to change the assignment unit of a task. Because when I assign a resource to a task with MaxUnits=50% the resource is overlocated.

So when I create the task in VBA I want to assign the MaxUnits of the resource to the task. 

I think this way the resource will not be overlocated. And I will build an audit I will get a good schedule.

My code:

projet.Tasks.Add (Lib_activite_courante)

        projet.Tasks(num_tache).ResourceNames = strRessourceName

        projet.Tasks(num_tache).Assignments.Add Units:= ???

Thank you for your help. 

Best regards,

Lula

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2015-08-10T18:11:38+00:00

Hello Lula,

You only need your second instruction as follows:

projet.tasks(num_tache).assignments.add Resource:=projet.resources(num_resource),units:=projet.resources(num_resource).maxunits

More elegant:

Set Reso=projet.resources(num_resource)

set Tac=projet.tasks(num_tache)

tac.assignments.add resource:=num_resource,units:=reso.maxunits

An alternative is your other approach:

projet.Tasks(num_tache).ResourceNames = strRessourceName

projet.Tasks(num_tache).Assignments(1).units=projet.resources(num_resource).maxunits

(only works if this is the first resource)

.. and there are more combinations

Greetings,

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Anonymous
    2015-08-11T17:57:48+00:00

    Hi Lula,

    I see some problems with your code:

    First, the instruction  projet.Tasks(num_tache).ResourceNames = strRessourceName

    is not just useless, it is also harmful - I'm afraid you will have an execution error since you are trying to connect the resource to the task twice. Eliminate this statement.

    Also, I don't understand the logic behind

     If (projet.Resources(R).ID = projet.Tasks(num_tache).ID) Then

    Are you looking ofr the resource with the same ID as the task? weird!

    Don't you mean

     If projet.Resources(R).name= strRessourcename Then

    You change Duration yourself when dividing it by resources.count. Isn't that what bothers you?

    Do keep me posted on the progress.

    Greetings,

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2015-08-11T15:45:26+00:00

    Hello Jan,

    Thanks for your help!

    I used this:

    projet.tasks(num_tache).assignments.add Resource:=projet.resources(num_resource),units:=projet.resources(num_resource).maxunits

    My code:

    projet.Tasks.Add (Lib_activite_courante)

            projet.Tasks(num_tache).ResourceNames = strRessourceName

            For R = 1 To projet.Resources.Count

                If (projet.Resources(R).ID = projet.Tasks(num_tache).ID) Then

                projet.Tasks(num_tache).Assignments.Add Resource:=projet.Resources(R), Units:=projet.Resources(R).MaxUnits

                End If

            Next R

            projet.Tasks(num_tache).Duration = strDuration * 7 * 60 / projet.Tasks(num_tache).Resources.Count

            projet.Tasks(num_tache).text1 = Mid$(Lib_activite_courante, InStr(Lib_activite_courante, "]") + 1)

            projet.Tasks(num_tache).Name = Num_activite_courante

    But I have a problem: MS Project changes the duration! My resource has a part time job (50%). 

    When the duration of the task is 15 days, Ms project changes it with 7,5 days!!

    Is it normal? How can I change that?

    Was this answer helpful?

    0 comments No comments