VBA: Adding assignment to the task

U

ugainedi

Hi Guys,
I am exporting data from MS Excel to MS Project using VBA.
want to do resource allocation programmatically based on their wor
hours.

I am getting an error

Runtime Error : 1101
The argument value is not valid

Dim t As Task
t.Assignments.Add TaskID:=4, ResourceID:='test', Units:= 'hrs/meeting'
t.Assignments.Add TaskID:=4, ResourceID:='test1', Units:
'hrs/meeting'

Can you please help me?

Thank
 
U

ugainedi

Thank you Jan. I removed the task id, but am still getting the same
error.
Any idea what I am doing wrong? I really appreciate your help


t.Assignments.Add ResourceID:='test' , Units:='Hours'


Thank you
 
B

BillB

ResourceID is not a string field, it's numeric. And Units is the number of
units to allocate. Check the Help file.

t.Assignments.Add ResourceID:=t.parent.Resources("test").ID, Units:=1

Bill B
 
M

Mike Glen

Hi ugainedi,

Next time, try posting on the developer newsgroup as this one is closing
down. Please see FAQ Item: 24. Project Newsgroups. FAQs, companion products
and other useful Project information can be seen at this web
address:http://project.mvps.org/faqs.htm .

Mike Glen
Project MVP
 
U

ugainedi

Thank you so much Bill. I really appreciate you answering my question.
But unfortunatly i am still getting a type mismatch error

t.Assignments.Add ResourceID:=t.Resources("test").id, Units:=8

Do you have any idea ? Thanks again
 
H

Hernán Mario

Hi, here you have the solution
Look that first set a new instance of a task in the activeproject.Add
method.
Then create a function getResID.

Regards

Hernán Mario

Sub test()
Dim t As Task
Set t = ActiveProject.Tasks.Add("New")
t.Assignments.Add ResourceID:=getResID("test"), Units:=8
End Sub

Function getResID(ResName As String) As Integer
Dim res As Resource
For Each res In ActiveProject.Resources
If res.Name = ResName Then
getResID = res.UniqueID
Exit Function
End If
getResID = -1
Next
End Function
 
H

Hernán Mario

Ok,, here is the correct code
Thanks
Hernán Mario

Sub test()


Dim t As Task
Set t = ActiveProject.Tasks.Add("New")
t.Assignments.Add ResourceID:=getResID("test"), Units:=8
End Sub

Function getResID(ResName As String) As Integer

Dim res As Resource
For Each res In ActiveProject.Resources
If res.Name = ResName Then

getResID = res.ID ****************************************

Exit Function
End If
getResID = -1
Next
End Function
 

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