change font for task.name and color of gantt bar based on criteria

B

bstandkeiii

I have the following code which changes color of gantt bars based on some
criteria. How do I change the font color of the associated task name. I
have tried a number of things without success.

Sub setganttcolor()
'This macro shows how to set a barstyle depending on a certain
'value in the text5 field. Right now the case statement is
'commented out, so it will make all of your tasks green
'If you comment out the green line, this macro is useful
'to clear any custom formatting that you may have applied to
'specific tasks.

'Copyright Jack Dahlgren, Feb. 2002
On Error GoTo setganttcolorend
Dim ts As Tasks
Set ts = ActiveProject.Tasks
Dim t As Task
Dim i As Integer
For Each t In ActiveProject.Tasks
i = i + 1
Select Case t.Text1
Case "p"
GanttBarFormat TaskID:=t.ID, Reset:=True
GanttBarFormat TaskID:=t.ID, MiddleColor:=pjPurple,
MiddlePattern:=pjSolidFillPattern, StartColor:=pjPurple, EndColor:=pjPurple
Case "g"
GanttBarFormat TaskID:=t.ID, Reset:=True
GanttBarFormat TaskID:=t.ID, MiddleColor:=pjGreen,
MiddlePattern:=pjSolidFillPattern, StartColor:=pjGreen, EndColor:=pjGreen
Case "r"
SelectTaskColumn ("name")
Font Bold:=True, Color:=pjRed
GanttBarFormat TaskID:=t.ID, Reset:=True
GanttBarFormat TaskID:=t.ID, MiddleColor:=pjRed,
MiddlePattern:=pjSolidFillPattern, StartColor:=pjMaroon, EndColor:=pjMaroon
Case "y"
GanttBarFormat TaskID:=t.ID, Reset:=True
GanttBarFormat TaskID:=t.ID, MiddleColor:=pjLime,
MiddlePattern:=pjSolidFillPattern, StartColor:=pjLime, EndColor:=pjLime
Case "b"
GanttBarFormat TaskID:=t.ID, Reset:=True
GanttBarFormat TaskID:=t.ID, MiddleColor:=pjBlue,
MiddlePattern:=pjSolidFillPattern, StartColor:=pjLime, EndColor:=pjLime

Case Else

End Select
Next t
setganttcolorend:
End Sub



Thanks in avance
 
R

Rod Gill

You don't actually need VBA for this. To change bar colors, simply add a
formula to a Flag field to set it to Yes if your criteria are met. Then set
the Marked field for each Task as well. Create a bar style based on Flag
field for bars and a text style for marked fields and you have what you
want.

--

Rod Gill
Project MVP

Project VBA Book, for details visit:
http://www.projectvbabook.com

NEW!! Web based VBA training course delivered by me. For details visit:
http://projectservertraining.com/learning/index.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top