Solved

Conditional formatting of task text in MS Project, 2003

Posted on 2006-11-06
8
3,541 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Project 2013 - "there has been a problem"... 9 463
Simple Gantt chart tool 4 306
Run Task consecutively in MS Project 2 237
Microsoft Project 2016 -- standard vs pro ? 2 176
At the office, we’ve started to get serious about organizing what we’re doing. I mean, it was getting to the point where every time I received a phone call, it began with “I know you’re really busy, but…” My boss was taking tasks away from me left a…
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

713 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