Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Conditional formatting of task text in MS Project, 2003

Posted on 2006-11-06
8
Medium Priority
?
3,575 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: x-men
Where used to see Gantt charts for illustrating project timelines, but what if I wanted to visualize passed timed events? Here's how.
Learn how ViaSat reduced average response times for IT incidents from 10 minutes to 30 seconds.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

647 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