Gantt Style Index

S

Steve P

Is there any way to programically determine the GanttStyle index as
required by the code snippet

GanttBarFormat TaskID:=74, GanttStyle:=13, StartShape:=2,
StartType:=0, StartColor:=3, etc

e.g How do I programmically determine that task 74 has a ganttstyle of
13

Thanks for any help you can give

Steve
 
J

Jack D.

Steve said:
Is there any way to programically determine the GanttStyle index as
required by the code snippet

GanttBarFormat TaskID:=74, GanttStyle:=13, StartShape:=2,
StartType:=0, StartColor:=3, etc

e.g How do I programmically determine that task 74 has a ganttstyle of
13

Thanks for any help you can give

Steve

You can't read it, but you can set it.
So set it to what you want and you will know what it is set to.
Relying on formatting to determine anything about a task is not a good idea.
Instead use outline codes, text fields or other non-volitile methods of
storing information about a task.
With a single click on a different view and the formatting completely
changes making your code break.

--
Please try to keep replies in this group. I do check e-mail, but only
infrequently. For Macros and other things check http://masamiki.com/project

-Jack Dahlgren, Project MVP
email: J -at- eM Vee Pee S dot COM


+++++++++++++++++++
 
S

Steve P

Thanks for confirming what I thought. Could you expand on the
statement "but you can set it". Programically how do I set it? I
assume using GanttBarFormat TaskID:=74, GanttStyle:=SomeOtherValue.
Just as importantly, if I cannot read the apparently non existant
'Style collection', how would I know what value to use? As I
understand it each file that this code will be applied to, can have
different styles defined and I am unsure as to how you can know what
the summary style index will be in each file

The situation I am in in that I am a power VBA user within my company
and another colleague has turned to me for help with Project, which is
not my strongest area. His bosses want to see a printed gannt chart
that inludes all tasks, but have some of them highlighted according to
criteria. Their thinking was that the bars should be differenet
colours. Is there a more Project way of achieving this?
Thanks for any help
Steve
 
J

Jack D.

You can do what you want without any VBA or with some VBA if you like.
First - go to format menu/barstyles and create a bar style that is the color
they want.
In the "show for" column select Flag1 (or any other flag field)
Now set flag 1 to true for that task (either by filling in the field
manually or by supplying a custom formula for that field or by using a VBA
macro to programmatically set the value) and the bar will show. If you make
the new bar so that it covers any other bars and put it last in the list you
will have no problem.

You can also create a highlight filter which will turn the text (on the left
side) whatever color you want.

Sub Macro1()
FilterEdit Name:="Foo", TaskFilter:=True, Create:=True,
OverwriteExisting:=True, FieldName:="Flag1", Test:="equals", Value:="yes",
ShowInMenu:=True, ShowSummaryTasks:=False
FilterApply Name:="Foo", Highlight:=True
TextStyles Item:=7, Size:="12"
End Sub

WHat are the criteria they want to use?


Steve said:
Thanks for confirming what I thought. Could you expand on the
statement "but you can set it". Programically how do I set it? I
assume using GanttBarFormat TaskID:=74, GanttStyle:=SomeOtherValue.
Just as importantly, if I cannot read the apparently non existant
'Style collection', how would I know what value to use? As I
understand it each file that this code will be applied to, can have
different styles defined and I am unsure as to how you can know what
the summary style index will be in each file

The situation I am in in that I am a power VBA user within my company
and another colleague has turned to me for help with Project, which is
not my strongest area. His bosses want to see a printed gannt chart
that inludes all tasks, but have some of them highlighted according to
criteria. Their thinking was that the bars should be differenet
colours. Is there a more Project way of achieving this?
Thanks for any help
Steve



--
Please try to keep replies in this group. I do check e-mail, but only
infrequently.
For Macros and other things check http://masamiki.com/project

-Jack Dahlgren, Project MVP
email: J -at- eM Vee Pee S dot COM


+++++++++++++++++++
 
S

Steve P

Thanks jack for your help, its greatly appreciated. It pushed me in
the correct direction and all works as desired. The code I came up
with is posted below, in case it helps anyone else.

regards
Steve


This code is designed to change the colour of all summary tasks that
contain the text "INSPN & HIGH PRIORITY ITEMS" in the task name.
It is designed to be used by only a few users, hence the use of msgbox
functions to cope with errors. Real code would need better error
handling!

If you copy and paste this code, you will need to correct for the
extra line breaks that have been added by Google Groups. (Lines ending
in the _ character are meant to wrap to the next line)

' You only need to run the ChangeBarColour function.
' It will allow you to only run the one time
' It has no dependnacy on the state of the project other
' than the following assumptions
'
' Assumption: Task Flag1 property is not used for anything else
' Assumption: BarStyle Highlight is not used for anything else
' Assumption: Standard Summary BarStyle exist and is not renamed
'
Public Sub sjpChangeBarColour()
'
Dim T As Task
Dim R As Resource
Dim TR As Resource
' Adds a style to be used by the INSP task and
' modifies the existing Summary style, so it is not
If sjpCreateBarStyle() Then
' Loop thur looking for all tasks that have the text
For Each T In ActiveProject.Tasks
'
If InStr(T.Name, "INSPN & HIGH PRIORITY ITEMS") Then
' It must be a summary task for the Highlight style to
work
If T.Summary Then
' Task is a summary and has the correct text, so
set Flag1
' The Highlight Bar Style will automatically react
to the
' flag and change its colour
T.Flag1 = True
'
Else
' Not a summary so we are in unanticipated area
MsgBox "Tried to change a bar color that was not
for a summary" & vbCrLf & _
"Contact Name" & vbCrLf & _
"Problem Task is on line: " & T.ID &
vbCrLf & _
"Press OK to continue updating bar
colours", vbInformation + vbOKOnly, "Unexpected Task Type"
End If
'
Else
' Didn't have the text so reset the flag to be sure it
' is as I want
T.Flag1 = False
'
End If
'
Next T
'
End If
End Sub
'
Function sjpCreateBarStyle() As Boolean
'
On Error GoTo err_handler
'
' Assume failure until all is well
sjpCreateBarStyle = False
'
If Not sjpStyleExist("Highlight") Then
' Does the standard BarStyle of Summary Exist
If sjpStyleExist("Summary") Then
' Adjust the current summary style so it is not applied
' when Flag1 is true
GanttBarStyleEdit Item:="Summary", ShowFor:="Summary,Not
Flag1"
' Add a new style (Highlight) that will be used by tasks
that have their Flag1
' property set to Yes
GanttBarStyleEdit Item:="Summary", Create:=True,
Name:="Highlight", _
StartShape:=2, StartType:=0,
StartColor:=3, _
MiddleShape:=2,
MiddleColor:=3, EndShape:=2, _
EndType:=0,
EndColor:=3, ShowFor:="Flag1"
'
sjpCreateBarStyle = True
'
Else
MsgBox "The standard barstyle 'Summary' could not be
found." & vbCrLf & _
"No action will be taken." & vbCrLf & _
"Contact Name goes here" _
, vbInformation + vbOKOnly, "Missing BarStyle"

End If
'
Else
MsgBox "You have already run this code on this project." &
vbCrLf & _
"No action will be taken." & vbCrLf & _
"Contact name goes here" _
, vbInformation + vbOKOnly, "Highlighting Already
Applied"

End If
'
exit_routine:
'
On Error GoTo 0
Exit Function
'
err_handler:
'
MsgBox "Error creating new style for High Priority Items" & vbCrLf
& _
"Contact name goes here" _
, vbInformation + vbOKOnly, "Unexpected Error"
'
Resume exit_routine
'
End Function
'
Public Function sjpStyleExist(strStyleName As String) As Boolean
'
On Error Resume Next
' Try to edit the style and see if an error occurs.
' If it does the style does not exist
' Ensure error object starts clean
Err.Clear
' Try and edit the style (without changing anything)
GanttBarStyleEdit Item:=strStyleName
' If we got an error
If Err.Number > 0 Then
' The style does not exist
StyleExist = False
Else
' No error, so we have a valid style
StyleExist = True
'
End If
'
On Error GoTo 0
'
End Function
 
J

Jack D.

Glad to be of help and thanks for posting back what you came up with.

-Jack

Steve said:
Thanks jack for your help, its greatly appreciated. It pushed me in
the correct direction and all works as desired. The code I came up
with is posted below, in case it helps anyone else.

regards
Steve


This code is designed to change the colour of all summary tasks that
contain the text "INSPN & HIGH PRIORITY ITEMS" in the task name.
It is designed to be used by only a few users, hence the use of msgbox
functions to cope with errors. Real code would need better error
handling!

If you copy and paste this code, you will need to correct for the
extra line breaks that have been added by Google Groups. (Lines ending
in the _ character are meant to wrap to the next line)

' You only need to run the ChangeBarColour function.
' It will allow you to only run the one time
' It has no dependnacy on the state of the project other
' than the following assumptions
'
' Assumption: Task Flag1 property is not used for anything else
' Assumption: BarStyle Highlight is not used for anything else
' Assumption: Standard Summary BarStyle exist and is not renamed
'
Public Sub sjpChangeBarColour()
'
Dim T As Task
Dim R As Resource
Dim TR As Resource
' Adds a style to be used by the INSP task and
' modifies the existing Summary style, so it is not
If sjpCreateBarStyle() Then
' Loop thur looking for all tasks that have the text
For Each T In ActiveProject.Tasks
'
If InStr(T.Name, "INSPN & HIGH PRIORITY ITEMS") Then
' It must be a summary task for the Highlight style to
work
If T.Summary Then
' Task is a summary and has the correct text, so
set Flag1
' The Highlight Bar Style will automatically react
to the
' flag and change its colour
T.Flag1 = True
'
Else
' Not a summary so we are in unanticipated area
MsgBox "Tried to change a bar color that was not
for a summary" & vbCrLf & _
"Contact Name" & vbCrLf & _
"Problem Task is on line: " & T.ID &
vbCrLf & _
"Press OK to continue updating bar
colours", vbInformation + vbOKOnly, "Unexpected Task Type"
End If
'
Else
' Didn't have the text so reset the flag to be sure it
' is as I want
T.Flag1 = False
'
End If
'
Next T
'
End If
End Sub
'
Function sjpCreateBarStyle() As Boolean
'
On Error GoTo err_handler
'
' Assume failure until all is well
sjpCreateBarStyle = False
'
If Not sjpStyleExist("Highlight") Then
' Does the standard BarStyle of Summary Exist
If sjpStyleExist("Summary") Then
' Adjust the current summary style so it is not applied
' when Flag1 is true
GanttBarStyleEdit Item:="Summary", ShowFor:="Summary,Not
Flag1"
' Add a new style (Highlight) that will be used by tasks
that have their Flag1
' property set to Yes
GanttBarStyleEdit Item:="Summary", Create:=True,
Name:="Highlight", _
StartShape:=2, StartType:=0,
StartColor:=3, _
MiddleShape:=2,
MiddleColor:=3, EndShape:=2, _
EndType:=0,
EndColor:=3, ShowFor:="Flag1"
'
sjpCreateBarStyle = True
'
Else
MsgBox "The standard barstyle 'Summary' could not be
found." & vbCrLf & _
"No action will be taken." & vbCrLf & _
"Contact Name goes here" _
, vbInformation + vbOKOnly, "Missing BarStyle"

End If
'
Else
MsgBox "You have already run this code on this project." &
vbCrLf & _
"No action will be taken." & vbCrLf & _
"Contact name goes here" _
, vbInformation + vbOKOnly, "Highlighting Already
Applied"

End If
'
exit_routine:
'
On Error GoTo 0
Exit Function
'
err_handler:
'
MsgBox "Error creating new style for High Priority Items" & vbCrLf
& _
"Contact name goes here" _
, vbInformation + vbOKOnly, "Unexpected Error"
'
Resume exit_routine
'
End Function
'
Public Function sjpStyleExist(strStyleName As String) As Boolean
'
On Error Resume Next
' Try to edit the style and see if an error occurs.
' If it does the style does not exist
' Ensure error object starts clean
Err.Clear
' Try and edit the style (without changing anything)
GanttBarStyleEdit Item:=strStyleName
' If we got an error
If Err.Number > 0 Then
' The style does not exist
StyleExist = False
Else
' No error, so we have a valid style
StyleExist = True
'
End If
'
On Error GoTo 0
'
End Function



--
Please try to keep replies in this group. I do check e-mail, but only
infrequently.
For Macros and other things check http://masamiki.com/project

-Jack Dahlgren, Project MVP
email: J -at- eM Vee Pee S dot COM


+++++++++++++++++++
 

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