V
VaReTaS
Hi,
I'm trying to make a macro that automatically assigns resources to tasks,
depending on the values of two custom text fields.
Imagine, that in the Gantt Chart view I've two custom fields, "text1" and
"text4", and the same thing in resource view, so if I put in the gantt view
text1="E1", and text4="F1" (or anything else), the macro should assign to
each task the resources that have text1="E1" and text4="F1" (or anything
else, depending on the text), based in the resource list field.
But everytime I tryed to ran the macro, the Microsoft Project crashes itself
for a long time and stop running.
The code i'm usign is this one:
--- code ---
Sub AutoAssign()
Dim tskT As Task
Dim rcsR As Resource
Dim asnA As Assignment
Dim lngUnits As Long
Dim blnFound As Boolean
lngUnits = 1
For Each tskT In ActiveProject.Tasks
If Not (tskT Is Nothing) Then
For Each rcsR In ActiveProject.Resources
If Not (rcsR Is Nothing) Then
If (rcsR.Text1 = tskT.Text1) And (rcsR.Text4 = tskT.Text4)
Then
For Each asnA In tskT.Assignments
If asnA.ResourceID = rcsR.ID Then
blnFound = True
End If
Next asnA
If blnFound = False Then
tskT.Assignments.Add TaskID:=tskT.ID,
ResourceID:=rcsR.ID, Units:=lngUnits
Else
blnFound = False
End If
End If
End If
Next rcsR
End If
Next tskT
End Sub
--- End Code ---
I don't know what is happening but it crashes everytime, in MS Project 2003
and even in MS Project 2007.
I hope someone can help me figuring it out, cause I don't know what to do
more and how can I solve this.
Thanks in advance,
VaReTaS
I'm trying to make a macro that automatically assigns resources to tasks,
depending on the values of two custom text fields.
Imagine, that in the Gantt Chart view I've two custom fields, "text1" and
"text4", and the same thing in resource view, so if I put in the gantt view
text1="E1", and text4="F1" (or anything else), the macro should assign to
each task the resources that have text1="E1" and text4="F1" (or anything
else, depending on the text), based in the resource list field.
But everytime I tryed to ran the macro, the Microsoft Project crashes itself
for a long time and stop running.
The code i'm usign is this one:
--- code ---
Sub AutoAssign()
Dim tskT As Task
Dim rcsR As Resource
Dim asnA As Assignment
Dim lngUnits As Long
Dim blnFound As Boolean
lngUnits = 1
For Each tskT In ActiveProject.Tasks
If Not (tskT Is Nothing) Then
For Each rcsR In ActiveProject.Resources
If Not (rcsR Is Nothing) Then
If (rcsR.Text1 = tskT.Text1) And (rcsR.Text4 = tskT.Text4)
Then
For Each asnA In tskT.Assignments
If asnA.ResourceID = rcsR.ID Then
blnFound = True
End If
Next asnA
If blnFound = False Then
tskT.Assignments.Add TaskID:=tskT.ID,
ResourceID:=rcsR.ID, Units:=lngUnits
Else
blnFound = False
End If
End If
End If
Next rcsR
End If
Next tskT
End Sub
--- End Code ---
I don't know what is happening but it crashes everytime, in MS Project 2003
and even in MS Project 2007.
I hope someone can help me figuring it out, cause I don't know what to do
more and how can I solve this.
Thanks in advance,
VaReTaS