Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6939941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:41:22+00:00 2026-05-27T12:41:22+00:00

Got a problem with VBA using MS Project 2007. I have a Task Task

  • 0

Got a problem with VBA using MS Project 2007. I have a Task Task with 2 Assignments, including the Resources Foo (2 days of work) and Bar (5 days of work). Task is set to fixed work. Now, when adding additional or removing Assignments manually to/from the Task, all works as expected, nothing fancy happening. When using VBA, like the following, the other Assignments’ work values change.

' Adding an Assignment with the "Baz" Resource and 10d of work
Sub AddAssignment()
    Dim tskTask As Task
    Dim rsResource As Resource
    Dim asAssignment As Assignment

    Set tskTask = ActiveProject.Tasks(1)
    Set rsResource = ActiveProject.Resources("Baz")
    Set asAssignment = tskTask.Assignments.Add(tskTask.ID, rsResource.ID)
    asAssignment.Work = "10d"
End Sub

Before executing the script:

Task:
  Foo 16h
  Bar 40h

After executing the script:

Task:
  Foo 9,33h
  Bar 23,33h
  Baz 80h

So, actual question, what do I have to do different in order to keep the other Assignments’ work values?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:41:22+00:00Added an answer on May 27, 2026 at 12:41 pm

    Because the task is set to Fixed Work, when you add a resource assignment, it will keep the total work for the task the same. The problem arises when you want to add a resource and increase the total amount of work for the task.

    What’s happening in this case is that the total work was 56h. You add an assignment and the total work is still 56h. The ratio of the work is the same: 40%, 100%, and 100%, which works out to 9.33h, 23.33h, and 23.33h. Then the work for the last assignment is increased to 80h and the total work for the task is now 112.67h.

    The reason it works as you intend in the user-interface is because you are not just adding a new assignment and setting its work, but from the perspective of MS Project, you are also (re)setting the work on the existing resources.

    The solution to doing this in VBA is to emulate exactly what is happening in the UI–which includes resetting the work for the existing resources:

    Sub AddAssignment()
        Dim tskTask As Task
        Dim rsResource As Resource
        Dim asAssignment As Assignment
        Dim colAssn As Collection
        Dim iIdx As Integer
    
        Set tskTask = ActiveProject.Tasks(7)
        Set rsResource = ActiveProject.Resources("Baz")
        Set colAssn = New Collection
        For Each asAssignment In tskTask.Assignments
            colAssn.Add asAssignment.Work
        Next asAssignment
        Set asAssignment = tskTask.Assignments.Add(tskTask.ID, rsResource.ID)
        colAssn.Add 10 * 8 * 60 ' work is stored as minutes
        For iIdx = 1 To colAssn.Count
            tskTask.Assignments(iIdx).Work = colAssn(iIdx)
        Next iIdx
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am starting using FMOD API and I have got problem with sound playing.
Got a problem with a query I'm trying to write. I have a table
Got a problem with ComponentListener. I'm using it to check if a certain component
I have got problem with my shaders. I am trying to put textures and
I've got problem using generics. I'm creating an interface called IProblem , where each
I've got problem. I'm using windows.forms ListView to show some data and I need
I have got problem with this method: public List<int> menu_wid_w_kat() { DataSet1TableAdapters.menu_widac_wszystkoTableAdapter pk =
I've got problem with rake tasks. When I tried to execute any rake task
I have got problem with creation Mutex. I don't know why because server is
I got problem to request a PartialView using ajax In my point of view

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.