How to add resource for each task in the task Usage section using VBA RRS feed

  • Question

  • Hi all,

    I have tasks in MS project 2010, however I want to be able to add resources to each task in the task usage section using VBA.

    In the task usage section I want to be able to:

    a) add resources

    b) Select resources.

    It sounds simple but I have been trying for half a day with no progress. Can anyone be kind enough to share your code to do the above?

    Thanks in advance


    Wednesday, December 12, 2012 3:09 AM


All replies

  • Adding a resource is simple, the add method on a task object or the add method on a resource object. What do you mean by select a resource? to do what? Remember that there is no need to select any task or resource in VBA and in fact your code runs faster and more reliably if you don't select them.

    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    Wednesday, December 12, 2012 3:25 AM
  • Hi Rod Gill thanks for replying and the hint.

    However I can't seem to figure out how to use the .Add method. here is my code

    Dim tsks as Tasks

    Dim t as Task

    Set tsks = ActiveProject.Tasks

    Set Res = ActiveProject.Resources

    For Each t in tsks

            t.assignment.add ([TaskID], [ResourceID], [Units]) as Assignment

    next t

    This code keep giving me error. I know I am using it the wrong way. Can you please show me how to use it? The intend of this code is to loop through every task and add resources to every one of them.

    To answer your question I wanted to select resources so that I can see if I can use the ResourceAssignment method. Seems like the way you suggested is better.


    Wednesday, December 12, 2012 4:07 AM
  • I found out how to use it ma thanks heaps!!!!!!
    Wednesday, December 12, 2012 4:27 AM