Addressing the Task Name field format in Microsoft Project

P

PegLegPerk

Need help with Field addressing.
I am trying to write VBA code to set the color of the task name in a
Microsoft Project Gantt Chart field depending on several parameters. I need
to be able to reference a Project task name using VBA, and change the color,
etc. The following code will do this with one problem:

today = Now
For Each T In ActiveProject.Tasks
idNum = T.ID
uniqID = T.UniqueID
startDateP = T.Start
actFinD = T.ActualFinish
If actFinD <> "NA" Or startDateP > today Then
'task is finished
SelectTaskField Row:=idNum, Column:="Name", rowrelative:=False
FontEx Color:=0 'black
FontEx Bold:=False
End If
Next T

The problem: This (usually) works as long as each summary task is opened
up (i.e. unrolled?) so that idNum is also the correct row number for the
SelectTaskField. Otherwise if a summary task is rolled up, the
SelectTaskField will cause the wrong task to be selected. However, even if I
“unroll†every Summary task, I have found that sometimes the ID number does
not correspond to the row number.

I need a better way to select the task name prior to setting the format,
perhaps using the Unique ID. I have bought several books and found nothing,
On the Project help menu I can only find a reference that seems to indicate
that this type of reference is possible. Several places I have run across
this statement:

Project Help: The ID property changes when a task or resource moves to a
new location on the Task Sheet or Resource Sheet. Use the UniqueID property
if you want a constant reference to a task or resource.

How do I use the the UniqueID property?
 
J

Jan De Messemaeker

Hi,

How about this:


outlineshowalltasks
filterapply "All Tasks"
selectall
max=activeselection.tasks.count

Selectbeginning
for ctr=1 to max-1
selectcelldown
set job=activeselection.tasks(1)
'Now you are sure job IS the selected tasks, do whatever

next ctr




--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
 

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