Setting the Bar Styles for a task

P

Prasad Basani

Hi,

I am creating a new task with some subtasks. I want to set the BarStyles for
each subtask. I have some subtasks that are milestones and some that have a
duration. I want them to be displayed differently.

Can anybody point me to the piece of code that does that? I am new to
Microsoft Project.

Any help is appreciated!

Thanks
Prasad
 
J

Jan De Messemaeker

Hi Prasad,

Bar styles for milestones ARE different from what is shown on other tasks!

To your question, is this VBA code you look for?
The method to use is GanttBarStyleEdit
I copied the Help below.

HTH



GanttBarStyleEdit Method
See AlsoApplies ToExampleSpecifics

Changes or creates a Gantt bar style.


Syntax

expression .GanttBarStyleEdit(Item, Create, Name, StartShape, StartType,
StartColor, MiddleShape, MiddleColor, MiddlePattern, EndShape, EndType,
EndColor, ShowFor, Row, From, To, BottomText, TopText, LeftText, RightText,
InsideText)

expression Optional. An expression that returns an Application object.

Item Required Variant. The name or row number of the Gantt bar style to
change in the Bar Styles dialog box. (The Bar Styles dialog box appears when
you click Bar Styles on the Format menu.)

Create Optional Boolean. True if a new Gantt bar style is created and
inserted in the Bar Styles dialog box before the Gantt bar style specified
with Item . If Item is "-1", the new Gantt bar style is added to the end of
the list of styles. The default value is False.

Name Optional String. A new name for the Gantt bar.

StartShape Optional Long. The start shape of the Gantt bar. The default
value is pjNone. Can be one of the following PjBarEndShape constants:

Constant Description

pjNone None
pjHouseUp House
pjHouseDown Upside-down house
pjDiamond Diamond
pjCircleDiamond Circled diamond
pjTriangleUp Triangle pointing up
pjTriangleDown Triangle pointing down
pjTriangleRight Triangle pointing right
pjTriangleLeft Triangle pointing left
pjCircleTriangleUp Circled triangle pointing up
pjCircleTriangleDown Circled triangle pointing down
pjArrowUp Arrow pointing up
pjArrowDown Arrow pointing down
pjCircleArrowUp Circled arrow pointing up
pjCircleArrowDown Circled arrow pointing down
pjCaretDownTop Caret pointing down on the top half of the bar
pjCaretUpBottom Caret pointing up on the bottom half of the bar
pjLineShape Line
pjSquare Square
pjCircle Circle
pjStar Star




StartType Optional Long. The start type of the Gantt bar. Can be one of
the following PjBarType constants: pjDashed, pjFramed, or pjSolid. The
default value is pjSolid.

StartColor Optional Long. The start color of the Gantt bar. The default
value is pjBlue. Can be one of the following PjColor constants:

pjColorAutomatic pjNavy
pjAqua pjOlive
pjBlack pjPurple
pjBlue pjRed
pjFuchsia pjSilver
pjGray pjTeal
pjGreen pjYellow
pjLime pjWhite
pjMaroon




MiddleShape Optional Long. The middle shape of the Gantt bar. Can be one
of the following PjBarShape constants: pjNone, pjRectangleBar,
pjRectangleTop, pjRectangleMiddle, pjRectangleBottom, pjLineTop,
pjLineMiddle, or pjLineBottom. The default value is pjRectangleBar.

MiddleColor Optional Long. The middle color of the Gantt bar. Can be one
of the PjColor constants. The default value is pjBlue.

MiddlePattern Optional Long. The middle pattern of the Gantt bar. The
default value is pjMediumFillPattern. Can be one of the following
PjFillPattern constants:

pjDarkFillPattern pjLineCrossPattern
pjDiagonalCrossPattern pjLineHorizontalPattern
pjDiagonalLeftPattern pjLineVerticalPattern
pjDiagonalRightPattern pjMediumFillPattern
pjHollowPattern pjSolidFillPattern
pjLightFillPattern




EndShape Optional Long. The end shape of the Gantt bar. Can be one of
the PjBarEndShape constants. The default value is pjNone.

EndType Optional Long. The end type of the Gantt bar. Can be one of the
following PjBarType constants: pjDashed, pjFramed, or pjSolid. The default
value is pjSolid.

EndColor Optional Long. The end color of the Gantt bar. Can be one of
the PjColor constants. The default value is pjBlue.

ShowFor Optional String. One or more task types (such as normal, split,
summary, milestone, and so on) separated by the list separator character.

Row Optional Integer. A number from 1 to 4 that specifies the row in
which the Gantt bar appears. The default value is 1.

From Optional String. The name of a date field specifying the start of
the Gantt bar.

To Optional String. The name of a date field specifying the end of the
Gantt bar.

BottomText Optional String. The task field to display below the Gantt
bar.

TopText Optional String. The task field to display above the Gantt bar.

LeftText Optional String. The task field to display to the left of the
Gantt bar.

RightText Optional String. The task field to display to the right of the
Gantt bar.

InsideText Optional String. The task field to display inside the Gantt
bar.


Remarks
The Bar Styles dialog box can contain up to 40 style entries.

Example
The following example creates a new bar style that consists of a light green
color and ends with a star shape.

Sub ModifyGanttBar()
GanttBarStyleEdit Item:=-1, Create:=True, Name:="My New Bar Style",
MiddleColor:=pjLime, EndShape:=pjStar
End Sub
 
P

Prasad Basani

Jan,

Thanks for you reply. I am using the following code to change the BarStyle
on a milestone:

Set subTask = ActiveProject.Tasks.Add("Mob")
If Not IsNull(rs!MOBDate) Then
subTask.Start = CDate(rs!MOBDate)
subTask.Milestone = True
GanttBarFormat TaskID:=subTask.ID, StartShape:=pjStar,
StartType:=pjSolid, StartColor:=pjRed, RightText:="Name"
End If

If I use the same method for a task which is not a milestone, it works. I
don't know why it is not working for a milestone. Do I have to delete the
default BarStyle for the milestone before running the above code?

Can you please help me on this?

Thanks
Prasad
 
J

Jan De Messemaeker

Hi,

I recorded a macro to do it, adapted it to your problem, and the following
works:
GanttBarFormat TaskID:=subtask.ID, GanttStyle:=4, StartShape:=pjStar,
StartType:=pjSolid, StartColor:=pjRed, RightText:="Name"

Make sure "GanttStyle" is the position of "Milestone" in the BarStyles list

HTH
 
P

Prasad Basani

Jan,

Thanks for the prompt reply.

-Prasad

Jan De Messemaeker said:
Hi,

I recorded a macro to do it, adapted it to your problem, and the following
works:
GanttBarFormat TaskID:=subtask.ID, GanttStyle:=4, StartShape:=pjStar,
StartType:=pjSolid, StartColor:=pjRed, RightText:="Name"

Make sure "GanttStyle" is the position of "Milestone" in the BarStyles list

HTH
 

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