changer la couleur du Gantt chart en fonction de la valeur de text

B

BradWong

Good morning,
I use Microsoft Project 2003 SP3, and I would like help about how with a vba
macro changed the color of my bar according to the value of my field.
I have three fields, one for the name, and the two others are for the date
of start and end of my action.
And so, I would like to change the color of my bar in green if there are
"electrical" in the field where are my action.
And if it is an other name I would like to have an other color, etc...

I try with that but it doesn't work

If ActiveProject.Tasks.Item.Text7.value = "electrical" Then

GanttBarStyleEdit startcolor:=pjGreen

End If


Thank you
 
J

Jan De Messemaeker

Hi,

You have taken so many (wrong, I'm sorry) assumptions that I first have to
point you towards FAQ 31 in
http://www.mvps.org/project/faqs.htm
where you learn how to make conditional coloring based on a flag field.

Then you can (even without VBA) set a formula in such a flag field (Tools,
customize, fields, look for Flag1 for instance)

In Flag1 firld you can use this formula

Iif(instr([Name];"Electrical");Yes;No)

As for doing it in VBA, you have to realize that you cannot set values for
the whole set of tasks, you have to handle them individually.

Following snippet may put you on the way:

Dim Job as task
For each Job in activeproject.tasks
if not job is nothing then
job.flag1=(instr(job.name,"Electrical")>0)
end if
next job

Hope this helps,

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
 
B

BradWong

Thank You very much
I succeeded in making what I wanted thanks to you


Jan De Messemaeker said:
Hi,

You have taken so many (wrong, I'm sorry) assumptions that I first have to
point you towards FAQ 31 in
http://www.mvps.org/project/faqs.htm
where you learn how to make conditional coloring based on a flag field.

Then you can (even without VBA) set a formula in such a flag field (Tools,
customize, fields, look for Flag1 for instance)

In Flag1 firld you can use this formula

Iif(instr([Name];"Electrical");Yes;No)

As for doing it in VBA, you have to realize that you cannot set values for
the whole set of tasks, you have to handle them individually.

Following snippet may put you on the way:

Dim Job as task
For each Job in activeproject.tasks
if not job is nothing then
job.flag1=(instr(job.name,"Electrical")>0)
end if
next job

Hope this helps,

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
BradWong said:
Good morning,
I use Microsoft Project 2003 SP3, and I would like help about how with a
vba
macro changed the color of my bar according to the value of my field.
I have three fields, one for the name, and the two others are for the date
of start and end of my action.
And so, I would like to change the color of my bar in green if there are
"electrical" in the field where are my action.
And if it is an other name I would like to have an other color, etc...

I try with that but it doesn't work

If ActiveProject.Tasks.Item.Text7.value = "electrical" Then

GanttBarStyleEdit startcolor:=pjGreen

End If


Thank you
 
J

Jan De Messemaeker

Hi,

This really makes me happy.

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
BradWong said:
Thank You very much
I succeeded in making what I wanted thanks to you


Jan De Messemaeker said:
Hi,

You have taken so many (wrong, I'm sorry) assumptions that I first have
to
point you towards FAQ 31 in
http://www.mvps.org/project/faqs.htm
where you learn how to make conditional coloring based on a flag field.

Then you can (even without VBA) set a formula in such a flag field
(Tools,
customize, fields, look for Flag1 for instance)

In Flag1 firld you can use this formula

Iif(instr([Name];"Electrical");Yes;No)

As for doing it in VBA, you have to realize that you cannot set values
for
the whole set of tasks, you have to handle them individually.

Following snippet may put you on the way:

Dim Job as task
For each Job in activeproject.tasks
if not job is nothing then
job.flag1=(instr(job.name,"Electrical")>0)
end if
next job

Hope this helps,

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
BradWong said:
Good morning,
I use Microsoft Project 2003 SP3, and I would like help about how with
a
vba
macro changed the color of my bar according to the value of my field.
I have three fields, one for the name, and the two others are for the
date
of start and end of my action.
And so, I would like to change the color of my bar in green if there
are
"electrical" in the field where are my action.
And if it is an other name I would like to have an other color, etc...

I try with that but it doesn't work

If ActiveProject.Tasks.Item.Text7.value = "electrical" Then

GanttBarStyleEdit startcolor:=pjGreen

End If


Thank you
 

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