Solved

Conditional formatting of task text in MS Project, 2003

Posted on 2006-11-06
8
3,485 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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

Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

12 Experts available now in Live!

Get 1:1 Help Now