?
Solved

Conditional formatting of task text in MS Project, 2003

Posted on 2006-11-06
8
Medium Priority
?
3,591 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
Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

 
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 500 total points
ID: 17898892
Post your complete code
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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…
Learn how ViaSat reduced average response times for IT incidents from 10 minutes to 30 seconds.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

807 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