Solved

Conditional formatting of task text in MS Project, 2003

Posted on 2006-11-06
8
3,511 Views
Last Modified: 2013-11-15
Hello:
In Microsoft Project, 2003, I'd like to conditionally set the color of the task text, based on the value of the task.  I found (and used) a variation of the VB code that dbase118 posted on 2/16/2006 to change the color of the bar, which worked beautifully (thanks dbase118):

Dim t As Task
      For Each t In ActiveProject.Tasks
     '************************************
     '* set bar & text color for "XYZ TASK"
     '************************************
      If Left(t.Name, 8) = "XYZ TASK" Then
        Application.GanttBarFormat TaskID:=t.ID, MiddleColor:=pjRed, StartColor:=pjRed, EndColor:=pjRed        
      End If          
     
     Next
Can you advise on how to change the color of the text on the Task, please?  
I'm new to project, new to VB.
THanks,
Betty
0
Comment
Question by:cninghm
  • 4
  • 4
8 Comments
 
LVL 5

Expert Comment

by:RobertoEscalanteTronco
ID: 17890092
This will change text color of a task to green.

Sub TASKCHANGECOLOR()
    SelectRange Row:=1, Column:=3
    Font Color:=9
End Sub

0
 

Author Comment

by:cninghm
ID: 17892687
Hi Roberto:
Thanks, but I'm having a bit of trouble with it.  I need to know how to refer to the particular row via a variable.  This isn't working.

Dim t As Task
For Each t In ActiveProject.Tasks
If Left(t.Name, 8) = "XYZ TASK" Then
        Application.GanttBarFormat TaskID:=t.ID, MiddleColor:=pjRed, StartColor:=pjRed, EndColor:=pjRed
         ' Sub TASKCHANGECOLOR()
           SelectRange Row:=t.ID, Column:=1
           Font Color:=3
         ' End Sub
 Next
     
       
      End If
0
 
LVL 5

Expert Comment

by:RobertoEscalanteTronco
ID: 17893714
You need to set the Relative Name
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 5

Expert Comment

by:RobertoEscalanteTronco
ID: 17893717
heres the complete code.
----------------------
Sub Macro1()
Dim t As Task
      For Each t In ActiveProject.Tasks
      If Left(t.Name, 8) = "XYZ TASK" Then
        Application.GanttBarFormat TaskID:=t.ID, MiddleColor:=pjRed, StartColor:=pjRed, EndColor:=pjRed
         SelectTaskField Row:=t, Column:="Name", RowRelative:=False
        Font Color:=3
      End If
     Next
End Sub
0
 

Author Comment

by:cninghm
ID: 17898439
Worked perfectly.  Thanks for your help.  

0
 

Author Comment

by:cninghm
ID: 17898856
Actually, on closer inspection, I just noticed it's one off.  Meaning, all bar colors with the first 8 characters of task name beginning with "XYZ Task" are colored correctly, but the task names begin getting colored after the first task beginning with "XYZ Task"
e.g.,
Task                                         Bar
.
.
.              
XYZ Task (Blue text)                  Red bar
XYZ Task (Red text)                   Red bar
XYZ Task (Red text)                   Red bar
ABC Task (Red text)                   Pink bar
ABC Task (Pink text)                  Pink bar
ABC Task (Pink text)                  Pink bar

XYZ task should all have red text. ABC Tasks should all have Pink text.
Not sure why this is happening.
0
 

Author Comment

by:cninghm
ID: 17898883
I changed the code:

SelectTaskField Row:=t,
to
SelectTaskField Row:=t -1

and it worked, but not sure why, since the bar reference is to t (not t-1)
0
 
LVL 5

Accepted Solution

by:
RobertoEscalanteTronco earned 125 total points
ID: 17898892
Post your complete code
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PMP prep 5 102
summary task to add all previous tasks under it in addition to the automatic single subtask 2 110
Software quality certificate 3 87
Project Operations Manual 2 61
Re-planning is just as important as planning. MS Project files need to be updated regularly to reflect the current status of the project and to streamline the upcoming tasks. We have seen a lot of issues where project managers have not updated the p…
"Disruption" is the most feared word for C-level executives these days. They agonize over their industry being disturbed by another player - most likely by startups.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now