Problem with GanttBarFormat method

J

Jan

For external communication, I want to distinguish the external dependencies
in a project plan with a different color and the name of the party on which
the dependency is applicable.

The external dependencies are stored in the plan as "milestones" and their
task name starts with "[DEP]".

For some reason the macro I developed doesn't format the milestone, but it
will format it when I change the task from milestone to task.

If a use the "Format"->"Bar" option from the menu on a task of type
"milestone", I can change color, shape, bartext etc. and the desired
formatting appears. However, on a large project it is almost impossible to do
this formatting by hand for al external dependencies.

Any thoughts on the problem I am facing with the macro. Here is the macro code
Sub Mark_Color()

Dim var_task As Task
Dim zoek_string As String
Dim vColor As Long
Dim vCustomer As String

zoek_string = "[DEP]"
vColor = pjSilver
vCustomer = InputBox("This project is for the customer ? ", "Identify
customer")

For Each var_task In ActiveProject.Tasks
If Not var_task Is Nothing Then
If InStr(1, var_task.name, zoek_string, 1) Then
' Assign customer name to Text20, otherwise it doesn't work
var_task.Text20 = vCustomer
If var_task.Milestone = True Then
GanttBarFormat var_task.ID, , , , vColor
GanttBarFormat var_task.ID, , , , , , , , , , , , ,
"text20"
Repaint = True
Else
GanttBarFormat var_task.ID, , pjStar, pjSolid, vColor, ,
, vColor, pjStar, pjSolid, vColor, , "finish", "text20"
End If
End If
End If
Next var_task
End Sub
 
R

Rod Gill

External tasks already have a different bar format, provided they are not
milestones. If you specifically want some milestone tasks to have a
different format, I suggest you set Flag1 to Yes for them. Then have a Gantt
bar for all Flag1tasks.
 
J

Jan De Messemaeker

Dag Jan, met Jan hier :))

(I shall continue in English here, if you want to read me in Dutch there is
a Dutch NG:
microsoft.public.nl.office.project)

I somewhat reworked your sub because I hate, hate very much, having to count
a dozen of commas and then still have to lookup what you mean in the help.
Naming the parameters makes reading so much clearer!

After quite some testing I discovered the "optional" parameter ganttstyle is
not that optional, it seems to default to the #1 style so you could not
adapt a milestone type.
Don't forget to check whether the milestone type is number 4 on your bar
styles and if necessary change the number.

That will make it work.

Tot ziens, hier of in de NL groep?



Sub Mark_Color()

Dim var_task As Task
Dim zoek_string As String
Dim vColor As Long
Dim vCustomer As String

zoek_string = "[DEP]"
vColor = pjSilver
vCustomer = InputBox("This project is for the customer ? ", "Identify
customer ")

For Each var_task In ActiveProject.Tasks
If Not var_task Is Nothing Then
If InStr(1, var_task.Name, zoek_string, 1) Then
' Assign customer name to Text20, otherwise it doesn't work
var_task.Text20 = vCustomer
If var_task.Milestone = True Then
GanttBarFormat TaskID:=var_task.ID, ganttstyle:=4, startshape:=pjDiamond,
starttype:=pjSolid, _
startcolor:=vColor, middleshape:=pjNone, endshape:=pjNone,
righttext:="Text20"
Else
GanttBarFormat TaskID:=var_task.ID, startshape:=pjStar, starttype:=pjSolid,
_
startcolor:=vColor, middlecolor:=vColor, endshape:=pjStar, endtype:=pjSolid,
_
endcolor:=vColor, righttext:="finish", toptext:="text20"
End If
End If
End If
Next var_task
End Sub




--
Jan De Messemaeker, Microsoft Project Most Valuable Professional
http://users.online.be/prom-ade/
For FAQs: http://www.mvps.org/project/faqs.htm
Jan said:
For external communication, I want to distinguish the external dependencies
in a project plan with a different color and the name of the party on which
the dependency is applicable.

The external dependencies are stored in the plan as "milestones" and their
task name starts with "[DEP]".

For some reason the macro I developed doesn't format the milestone, but it
will format it when I change the task from milestone to task.

If a use the "Format"->"Bar" option from the menu on a task of type
"milestone", I can change color, shape, bartext etc. and the desired
formatting appears. However, on a large project it is almost impossible to do
this formatting by hand for al external dependencies.

Any thoughts on the problem I am facing with the macro. Here is the macro code
Sub Mark_Color()

Dim var_task As Task
Dim zoek_string As String
Dim vColor As Long
Dim vCustomer As String

zoek_string = "[DEP]"
vColor = pjSilver
vCustomer = InputBox("This project is for the customer ? ", "Identify
customer")

For Each var_task In ActiveProject.Tasks
If Not var_task Is Nothing Then
If InStr(1, var_task.name, zoek_string, 1) Then
' Assign customer name to Text20, otherwise it doesn't work
var_task.Text20 = vCustomer
If var_task.Milestone = True Then
GanttBarFormat var_task.ID, , , , vColor
GanttBarFormat var_task.ID, , , , , , , , , , , , ,
"text20"
Repaint = True
Else
GanttBarFormat var_task.ID, , pjStar, pjSolid, vColor, ,
, vColor, pjStar, pjSolid, vColor, , "finish", "text20"
End If
End If
End If
Next var_task
End Sub
 
J

Jan

Hoi Jan,

Thanks for the Reply. I applied your fix and after modifying the second
"Ganttbarformat"-statement (which also needed ganttstyle as parameter, at
least on my MSP installation) it worked.

One more question on this topic: How can I test whether a task is a normal
task. I know how to test for a milestone, but not how to test for an ordinary
task.

Thanks Jan


Jan De Messemaeker said:
Dag Jan, met Jan hier :))

(I shall continue in English here, if you want to read me in Dutch there is
a Dutch NG:
microsoft.public.nl.office.project)

I somewhat reworked your sub because I hate, hate very much, having to count
a dozen of commas and then still have to lookup what you mean in the help.
Naming the parameters makes reading so much clearer!

After quite some testing I discovered the "optional" parameter ganttstyle is
not that optional, it seems to default to the #1 style so you could not
adapt a milestone type.
Don't forget to check whether the milestone type is number 4 on your bar
styles and if necessary change the number.

That will make it work.

Tot ziens, hier of in de NL groep?



Sub Mark_Color()

Dim var_task As Task
Dim zoek_string As String
Dim vColor As Long
Dim vCustomer As String

zoek_string = "[DEP]"
vColor = pjSilver
vCustomer = InputBox("This project is for the customer ? ", "Identify
customer ")

For Each var_task In ActiveProject.Tasks
If Not var_task Is Nothing Then
If InStr(1, var_task.Name, zoek_string, 1) Then
' Assign customer name to Text20, otherwise it doesn't work
var_task.Text20 = vCustomer
If var_task.Milestone = True Then
GanttBarFormat TaskID:=var_task.ID, ganttstyle:=4, startshape:=pjDiamond,
starttype:=pjSolid, _
startcolor:=vColor, middleshape:=pjNone, endshape:=pjNone,
righttext:="Text20"
Else
GanttBarFormat TaskID:=var_task.ID, startshape:=pjStar, starttype:=pjSolid,
_
startcolor:=vColor, middlecolor:=vColor, endshape:=pjStar, endtype:=pjSolid,
_
endcolor:=vColor, righttext:="finish", toptext:="text20"
End If
End If
End If
Next var_task
End Sub




--
Jan De Messemaeker, Microsoft Project Most Valuable Professional
http://users.online.be/prom-ade/
For FAQs: http://www.mvps.org/project/faqs.htm
Jan said:
For external communication, I want to distinguish the external dependencies
in a project plan with a different color and the name of the party on which
the dependency is applicable.

The external dependencies are stored in the plan as "milestones" and their
task name starts with "[DEP]".

For some reason the macro I developed doesn't format the milestone, but it
will format it when I change the task from milestone to task.

If a use the "Format"->"Bar" option from the menu on a task of type
"milestone", I can change color, shape, bartext etc. and the desired
formatting appears. However, on a large project it is almost impossible to do
this formatting by hand for al external dependencies.

Any thoughts on the problem I am facing with the macro. Here is the macro code
Sub Mark_Color()

Dim var_task As Task
Dim zoek_string As String
Dim vColor As Long
Dim vCustomer As String

zoek_string = "[DEP]"
vColor = pjSilver
vCustomer = InputBox("This project is for the customer ? ", "Identify
customer")

For Each var_task In ActiveProject.Tasks
If Not var_task Is Nothing Then
If InStr(1, var_task.name, zoek_string, 1) Then
' Assign customer name to Text20, otherwise it doesn't work
var_task.Text20 = vCustomer
If var_task.Milestone = True Then
GanttBarFormat var_task.ID, , , , vColor
GanttBarFormat var_task.ID, , , , , , , , , , , , ,
"text20"
Repaint = True
Else
GanttBarFormat var_task.ID, , pjStar, pjSolid, vColor, ,
, vColor, pjStar, pjSolid, vColor, , "finish", "text20"
End If
End If
End If
Next var_task
End Sub
 
D

Dean C

Jan,
Use [Summary] = No to test for an ordinary task.


Also, if you split the external tasks out of your main schedule, you don't
need a macro.

External tasks are already formatted differently. You can change the way
they look by selecting FormatStylesItemToChangeExternalTasks.

Since you went to the trouble of writing a macro, your external tasks are
probably not truly external tasks. The process below is for splitting a
schedule into two schedules and re-establishing the logic.

1. Filter for your external tasks and if your filter used the task name,
insert a flag field and set the flag to yes for all external tasks.
2. Copy all of your external tasks and paste them in a new file, insert
columns Unique ID Predecessor and Unique ID Successor, then save the new file
in the same folder as the old file.
This will break predecessor and successor relationships between the new
copied tasks and the tasks not pasted in the new file. The original
relationships will remain intact.
3. Create a consolidated schedule comprising first the original schedule and
then, the new schedule.
4. Pick any of your orginal tasks and manually establish a link to one of
the new tasks. This will result in a Predecessor or Successor that looks
something like D:\Sample1.mpp\1.
5. Copy the string in front of the predecessor task number, for example,
D:\Sample1.mpp\ and paste it into cell A1 in an Excel worksheet.
6. Remove the link.
7. Open the window for your original file
8. Insert the fields UniqueID Predecessors and UniqueID Successors.
9. Select both columns, then copy and paste them into cell B1 in the same
Excel file as the external link example that you pasted in step 5.
10. In cell D1, enter the formula =$A$1 & B1
11. Fill the formula right, then down.
12. Copy the value from A1.
13. Select columns D and E.
14. Press Ctrl-H (replace), enter a comma "," for the Find What: value, then
enter a comma "," and press Ctrl-V (to paste the value from A1) in the
Replace with: field, then select ReplaceAll.
15. If any predecessors or successors were retained in the new file, copy
the new file Unique ID Predecessors and Unique ID Successors and paste into
F1.
16. If you did the step above, enter in cell H1, the formula =IF(OR(D1="",
F1=""),D1&F1,D1&","&F1)
17. Fill the formula from H1 across to I1 then down
18. Copy D1 to E?? or H1 to I?? and paste in the Unique ID Predecessors
Column in your new file.
19. This will result in external tasks being inserted in both your old and
new schedules, and IDs for all tasks changing. that is why it is important to
use Unique ID Predecessor and Unique ID Successor when copying and pasting
the logic.
20. Go to the consolidated schedule, filter for your external tasks, then
sort by task name. Be sure to de-select Keep Outline Structure. This will
result in having your duplicate tasks immediately below the original.
21. Spot check to verify that the new tasks are linked correctly. don't
worry if the new tasks are linked to the old external tasks and the new
external tasks.
22. When you are satisfied with the logic, return to the old schedule.
23. If you used the task name to filter for external tasks, Autofilter on
the flag field set in step 1 to hide the new external tasks.
24. Delete all of the original external tasks.
25. The old file will now show the external tasks grayed out, appearing near
the first task that they are linked to. Change the format if desired.
26 If the external tasks do not appear, Select ToolsOptionsView and select
Show External Predecessors and Show External Successors.
27. Save the Excel file for the next time you want to split a project.



Jan said:
Hoi Jan,

Thanks for the Reply. I applied your fix and after modifying the second
"Ganttbarformat"-statement (which also needed ganttstyle as parameter, at
least on my MSP installation) it worked.

One more question on this topic: How can I test whether a task is a normal
task. I know how to test for a milestone, but not how to test for an ordinary
task.

Thanks Jan


Jan De Messemaeker said:
Dag Jan, met Jan hier :))

(I shall continue in English here, if you want to read me in Dutch there is
a Dutch NG:
microsoft.public.nl.office.project)

I somewhat reworked your sub because I hate, hate very much, having to count
a dozen of commas and then still have to lookup what you mean in the help.
Naming the parameters makes reading so much clearer!

After quite some testing I discovered the "optional" parameter ganttstyle is
not that optional, it seems to default to the #1 style so you could not
adapt a milestone type.
Don't forget to check whether the milestone type is number 4 on your bar
styles and if necessary change the number.

That will make it work.

Tot ziens, hier of in de NL groep?



Sub Mark_Color()

Dim var_task As Task
Dim zoek_string As String
Dim vColor As Long
Dim vCustomer As String

zoek_string = "[DEP]"
vColor = pjSilver
vCustomer = InputBox("This project is for the customer ? ", "Identify
customer ")

For Each var_task In ActiveProject.Tasks
If Not var_task Is Nothing Then
If InStr(1, var_task.Name, zoek_string, 1) Then
' Assign customer name to Text20, otherwise it doesn't work
var_task.Text20 = vCustomer
If var_task.Milestone = True Then
GanttBarFormat TaskID:=var_task.ID, ganttstyle:=4, startshape:=pjDiamond,
starttype:=pjSolid, _
startcolor:=vColor, middleshape:=pjNone, endshape:=pjNone,
righttext:="Text20"
Else
GanttBarFormat TaskID:=var_task.ID, startshape:=pjStar, starttype:=pjSolid,
_
startcolor:=vColor, middlecolor:=vColor, endshape:=pjStar, endtype:=pjSolid,
_
endcolor:=vColor, righttext:="finish", toptext:="text20"
End If
End If
End If
Next var_task
End Sub




--
Jan De Messemaeker, Microsoft Project Most Valuable Professional
http://users.online.be/prom-ade/
For FAQs: http://www.mvps.org/project/faqs.htm
Jan said:
For external communication, I want to distinguish the external dependencies
in a project plan with a different color and the name of the party on which
the dependency is applicable.

The external dependencies are stored in the plan as "milestones" and their
task name starts with "[DEP]".

For some reason the macro I developed doesn't format the milestone, but it
will format it when I change the task from milestone to task.

If a use the "Format"->"Bar" option from the menu on a task of type
"milestone", I can change color, shape, bartext etc. and the desired
formatting appears. However, on a large project it is almost impossible to do
this formatting by hand for al external dependencies.

Any thoughts on the problem I am facing with the macro. Here is the macro code
Sub Mark_Color()

Dim var_task As Task
Dim zoek_string As String
Dim vColor As Long
Dim vCustomer As String

zoek_string = "[DEP]"
vColor = pjSilver
vCustomer = InputBox("This project is for the customer ? ", "Identify
customer")

For Each var_task In ActiveProject.Tasks
If Not var_task Is Nothing Then
If InStr(1, var_task.name, zoek_string, 1) Then
' Assign customer name to Text20, otherwise it doesn't work
var_task.Text20 = vCustomer
If var_task.Milestone = True Then
GanttBarFormat var_task.ID, , , , vColor
GanttBarFormat var_task.ID, , , , , , , , , , , , ,
"text20"
Repaint = True
Else
GanttBarFormat var_task.ID, , pjStar, pjSolid, vColor, ,
, vColor, pjStar, pjSolid, vColor, , "finish", "text20"
End If
End If
End If
Next var_task
End Sub
 
J

Jan De Messemaeker

Dag Jan,

I only can say that the "abnormal" conditions should be false:

atask.milestone
atask.summary

If they're both false the task shoyuld be "normal" isn't it?

--
Jan De Messemaeker, Microsoft Project Most Valuable Professional
http://users.online.be/prom-ade/
For FAQs: http://www.mvps.org/project/faqs.htm
Jan said:
Hoi Jan,

Thanks for the Reply. I applied your fix and after modifying the second
"Ganttbarformat"-statement (which also needed ganttstyle as parameter, at
least on my MSP installation) it worked.

One more question on this topic: How can I test whether a task is a normal
task. I know how to test for a milestone, but not how to test for an ordinary
task.

Thanks Jan


Jan De Messemaeker said:
Dag Jan, met Jan hier :))

(I shall continue in English here, if you want to read me in Dutch there is
a Dutch NG:
microsoft.public.nl.office.project)

I somewhat reworked your sub because I hate, hate very much, having to count
a dozen of commas and then still have to lookup what you mean in the help.
Naming the parameters makes reading so much clearer!

After quite some testing I discovered the "optional" parameter ganttstyle is
not that optional, it seems to default to the #1 style so you could not
adapt a milestone type.
Don't forget to check whether the milestone type is number 4 on your bar
styles and if necessary change the number.

That will make it work.

Tot ziens, hier of in de NL groep?



Sub Mark_Color()

Dim var_task As Task
Dim zoek_string As String
Dim vColor As Long
Dim vCustomer As String

zoek_string = "[DEP]"
vColor = pjSilver
vCustomer = InputBox("This project is for the customer ? ", "Identify
customer ")

For Each var_task In ActiveProject.Tasks
If Not var_task Is Nothing Then
If InStr(1, var_task.Name, zoek_string, 1) Then
' Assign customer name to Text20, otherwise it doesn't work
var_task.Text20 = vCustomer
If var_task.Milestone = True Then
GanttBarFormat TaskID:=var_task.ID, ganttstyle:=4, startshape:=pjDiamond,
starttype:=pjSolid, _
startcolor:=vColor, middleshape:=pjNone, endshape:=pjNone,
righttext:="Text20"
Else
GanttBarFormat TaskID:=var_task.ID, startshape:=pjStar, starttype:=pjSolid,
_
startcolor:=vColor, middlecolor:=vColor, endshape:=pjStar, endtype:=pjSolid,
_
endcolor:=vColor, righttext:="finish", toptext:="text20"
End If
End If
End If
Next var_task
End Sub




--
Jan De Messemaeker, Microsoft Project Most Valuable Professional
http://users.online.be/prom-ade/
For FAQs: http://www.mvps.org/project/faqs.htm
Jan said:
For external communication, I want to distinguish the external dependencies
in a project plan with a different color and the name of the party on which
the dependency is applicable.

The external dependencies are stored in the plan as "milestones" and their
task name starts with "[DEP]".

For some reason the macro I developed doesn't format the milestone, but it
will format it when I change the task from milestone to task.

If a use the "Format"->"Bar" option from the menu on a task of type
"milestone", I can change color, shape, bartext etc. and the desired
formatting appears. However, on a large project it is almost
impossible to
do
this formatting by hand for al external dependencies.

Any thoughts on the problem I am facing with the macro. Here is the
macro
code
Sub Mark_Color()

Dim var_task As Task
Dim zoek_string As String
Dim vColor As Long
Dim vCustomer As String

zoek_string = "[DEP]"
vColor = pjSilver
vCustomer = InputBox("This project is for the customer ? ", "Identify
customer")

For Each var_task In ActiveProject.Tasks
If Not var_task Is Nothing Then
If InStr(1, var_task.name, zoek_string, 1) Then
' Assign customer name to Text20, otherwise it doesn't work
var_task.Text20 = vCustomer
If var_task.Milestone = True Then
GanttBarFormat var_task.ID, , , , vColor
GanttBarFormat var_task.ID, , , , , , , , , , , , ,
"text20"
Repaint = True
Else
GanttBarFormat var_task.ID, , pjStar, pjSolid,
vColor,
,
, vColor, pjStar, pjSolid, vColor, , "finish", "text20"
End If
End If
End If
Next var_task
End Sub
 
J

Jan

Hi Dean,

Thanks for your reply. I didn't try your input yet, but I certainly will do so

Thanks

Jan
 
J

Jan

Dag Jan,

Thanks for your reply. That was also the solution I found, but I normally
would like to test the value I need instead of the values I don't need.

Bedankt / Thanks,

Jan
 

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

Similar Threads


Top