Change Color of 'Duration' field using VBA

Y

y7c4g2k5

I need VBA code that controls the 'Duration' cell Font Color - I'm using
a condition in another field to change the color depending on the
text/value found - this code has to be active while MS Project file is
opened. example below -

Sub DurationWhite()

Dim t as Task
Dim ts as Tasks

For Each t In ActiveProject.Task
If Not t Is Nothing Then
If t.Calendar= "5d/Wk w/Holidays 2shift-8hr ea" Then
t.duration.FontColor = 7 (**This does not Work!!)
End if
End if
Next t

End Sub

PS - Is it possible to use a wildcard instead of typing the entire
calendar title?
i.e. "*2shift*"
 
J

Jan De Messemaeker

Hi,

Font method in Project works on the activeselection.
You will have to select your cell (which is not obvious) then simply use the
Font method.
Hope this helps
 
Y

y7c4g2k5

Is there a method to have it work automatically for the entire project
versus having to select a particular task?
 
J

Jan De Messemaeker

Hi,

You can make it work for all tasks or for some "families" of tasks.
Look at Format, Text Styles.
You have All as an option or Summary Tasks, Critical Tasks, Milestone
Tasks...

In VBA there is the TextStyles method - see the help below.
Text Styles are saved WITH THE VIEW.

Hope this helps
----------------------------------------------------------------------
TextStyles Method


Sets the text styles for tasks and resources in the active view.

Syntax

expression.TextStyles(Item, Font, Size, Bold, Italic, Underline, Color)

expression Optional. An expression that returns an Application object.

Item Optional Long. The type of text to change. Can be one of the
following PjTextItem constants:

If the Gantt Chart is active:

pjAll pjGanttMinorTimescale
pjBarTextBottom pjMarked
pjBarTextInside pjMilestone
pjBarTextLeft pjNoncritical
pjBarTextRight pjProjectSummary
pjBarTextTop pjSummary
pjCritical pjTaskFilterHighlight
pjGanttExternalTask pjTaskRowColumnTitles
pjGanttMajorTimescale


If the Calendar view is active:

pjAll pjMarked
pjCalendarExternalTask pjMilestone
pjCalendarMonthlyTitles pjMonthPreviews
pjCritical pjNoncritical
pjDailyTitles pjProjectSummary
pjDateBoxBottomLeft pjSummary
pjDateBoxBottomRight pjTaskFilterHighlight
pjDateBoxTopLeft pjWeeklyTitles
pjDateBoxTopRight


If the Task Usage view is active:

pjAll pjTaskFilterHighlight
pjCritical pjTaskMajorTimescale
pjMarked pjTaskMinorTimescale
pjMilestone pjTaskRowColumnTitles
pjNoncritical pjTaskUsageAssignmentRow
pjProjectSummary pjTaskUsageExternalTask
pjSummary


If the Task Sheet is active:

pjAll pjProjectSummary
pjCritical pjSummary
pjMarked pjTaskSheetExternalTask
pjMilestone pjTaskFilterHighlight
pjNoncritical pjTaskRowColumnTitles


If the Resource Graph is active: pjAll, pjAllocated, pjOverallocated,
pjGraphMajorTimescale, pjGraphMinorTimescale, pjTickLabels, or
pjLegendLabels.

If the Resource Usage view is active: pjAll, pjAllocated, pjOverallocated,
pjResourceFilterHighlight, pjResourceRowColumnTitles,
pjResourceMajorTimescale, pjResourceMinorTimescale, or
pjResourceUsageAssignmentRow.

If the Resource Sheet is active: pjAll, pjAllocated, pjOverallocated,
pjResourceFilterHightlight, or pjResourceRowColumnTitles.

Font Optional String. The name of the font. The Font argument is ignored
if the active view is the Network Diagram and Item is not pjAll.

Size Optional Integer. The size of the font in points. The Size argument
is ignored if the active view is the Network Diagram and Item is not pjAll.

Bold Optional Boolean. True if the font is bold.

Italic Optional Boolean. True if the font is italic.

Underline Optional Boolean. True if the font is underlined.

Color Optional Long. The color of the font. Can be one of the following
PjColor constants:

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


Remarks

Using the TextStyles method without specifying any arguments displays the
Text Styles dialog box.
 

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