none
Replacing a resource RRS feed

  • Question

  • Hello,

    I am having difficulties consistently replacing an assigned resource with actual values using the following code:

    Dim rass as Assignment

    Dim res as Resource

    ResourceAssignment Resources:=rass.Resource.Name, Operation:=pjReplace, With:=Res.Name

    The rass.Resource work resource is assigned to a task with actual values and Res is an existing work resource in the resource pool that needs to replace rass.Resource. This has worked a couple times when I stepped through the code, but not 100% of the time, and it has never worked when I run the macro. When it doesn't replace the assigned resource (rass.resource.name), sometimes it adds the resource (res.name) and sometimes it does not. Other than not including "" around the resource names, which wouldn't apply when using the variables, I am fairly certain the syntax is accurate (I recorded a simple replacement macro). The help file contains limited helpful information, and I found only the MSDN page w/ additional info on this method (I scanned Rod's VBA Programming book, too).

    Could anyone provide some insight into the sporadic behavior I am experiencing (i.e. sometimes working, sometimes not)? Also, I would greatly appreciate any assistance/direction towards a known solution or workaround.

    Thank you,

    Ray

    Saturday, May 19, 2012 8:32 PM

Answers

  • By default the resource Actual hours are not replaced, only remaining work gets replaced. I had a 10d task with res assigned at 50% so 40h work.

    I set task to 50% and ran the following code:

    ResourceAssignment Resources:="res", Operation:=pjReplace, With:="Res2[50%]"

    The remaining work went to res2 and res only had actual work assigned. This is the behavior I expect and would advocate for. If percent complete is 0% then I expect all work to be reassigned.

    Can you confirm what % complete you have?


    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    • Marked as answer by youknowray Monday, May 21, 2012 12:20 AM
    Sunday, May 20, 2012 12:10 AM
    Moderator
  • Yes, but build the string: something like:

    ResourceAssignment Resources:="res", Operation:=pjReplace,_ 
        With:=ResName & "["& ResUnits &"]"


    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    • Marked as answer by youknowray Monday, May 21, 2012 12:20 AM
    Sunday, May 20, 2012 9:56 PM
    Moderator

All replies

  • By default the resource Actual hours are not replaced, only remaining work gets replaced. I had a 10d task with res assigned at 50% so 40h work.

    I set task to 50% and ran the following code:

    ResourceAssignment Resources:="res", Operation:=pjReplace, With:="Res2[50%]"

    The remaining work went to res2 and res only had actual work assigned. This is the behavior I expect and would advocate for. If percent complete is 0% then I expect all work to be reassigned.

    Can you confirm what % complete you have?


    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    • Marked as answer by youknowray Monday, May 21, 2012 12:20 AM
    Sunday, May 20, 2012 12:10 AM
    Moderator
  • Thank you for the reply, Rod. I was so far into the code that I didn't consider how Project actually handles replacing resources with actual work. As you probably suspected, Project's strange "behavior" was due to different work/actual values. I tested the code again with different work/actual work combinations and observed the following:

    - If the existing assignment has 0 remaining work (i.e. 100% complete), Project will prompt you to move all work/actual work to the replacement resource (dialog box can be overridden with Application.DisplayAlerts = false)

    - As Rod mentioned, if the existing assignment has > 0 remaining work, the remaining work will be moved to the new resource, and if percent complete is 0%, all work will be reassigned.

    One additional question regarding the ResourceAssignment method: is it possible to set the units in this method (like you did in your example) when using a variable for the resource name? I end up copying the assigned resources' units value into a variable before the replacement, then assigning the units to the new resource after the replacement.

    Thanks again for the info!

    Ray
    Sunday, May 20, 2012 9:09 PM
  • Yes, but build the string: something like:

    ResourceAssignment Resources:="res", Operation:=pjReplace,_ 
        With:=ResName & "["& ResUnits &"]"


    Rod Gill

    The one and only Project VBA Book

    Rod Gill Project Management

    • Marked as answer by youknowray Monday, May 21, 2012 12:20 AM
    Sunday, May 20, 2012 9:56 PM
    Moderator
  • Thanks again, Rod. I tried placing the brackets in double quotes before/after my units variable, but Project assigns the resource at 100% instead of 10%, the variable's value. I also tried plugging a numerical/% value in the brackets (e.g., "[50%]") with no luck. This isn't a big deal as I already have a workaround, but it would be nice to know for future projects.

    Thanks again for your help.

    Ray

    Monday, May 21, 2012 12:19 AM