Adding Resource Assignments to a Task via MS Visual Basic .NET

J

Joe Cletcher

I'm trying to add resources/assignments to a task by using the
"...Assignments.ADD" method. What is the correct syntax for executing the
following command?

MyProjTaskAssignment = aTask.Assignments.Add(aTask.Index, FteResourceID, 1)

where

DIM aTask as MSProject.Task
DIM FteResourceID as Long
DIM MyProjTaskAssignment as MSProject.Assignment
 
R

Rod Gill

For this sort of thing record a macro in Project of you adding an
assignment, then look at the recorded code. Click on each method and press
F1 for help. Experiment in VBA, get it as you want then copy the code to
VB.Net and edit to include the Projapp.aTask etc. You need to refer to a
Project Application object from VB.Net but not in Project VBA as Project
Object is assumed.
 
J

Jan De Messemaeker

Hi,

First, I only know VBA and not VB.Net but shouldn't that read
Set MyProjTask...
Since the resulting assignment is an oblject;

Secondly I don't know whgether in this sintax you have to repeat the taskID,
I would write this as

..add(resourceID:=FteResourceID)


HTH
 
R

Rod Gill

Hi,

You don't need Set in VB.Net. For the rest I would copy paste form working
VBA code to VB.Net and add the Project Application Object in front of all
Project methods and Properties as being the easiest way to develop the code.
 
J

Joe Cletcher

The "Assignments.Add" method doesn't seem to work or the perferred method is
the "ResourceAssignment" method. I had tried the "ResourceAssignment" method
earlier but was unsuccessful--your comment about pressing F1 for help was the
helpful part. The "help" for the "ResourceAssignment" method stated that it
had to be called by a MS Project Application object such as indicated below.

Dim aTask as MSProject.Task
Dim myProjApp as New MSProject.Application
.......
myProjApp.SelectTaskCell(aTask.ID, , RowRelative:=False)
myProjApp.ResourceAssignment(Resources:="fte",
Operation:=PjResAssignOperation.pjAssign, With:="")
.......
 

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