J
Jane
I am having a hard time getting the font color to change.
Here's some sample code:
// Apply Status Impact View
ViewProcessing.Apply(project, Parameters.Views.vwStatusImpact);
// Select the entire sheet
project.Application.SelectSheet();
for (int taskIdx = 1; taskIdx <
project.Application.ActiveSelection.Tasks.Count; taskIdx++)
{
MsProject.Task task = project.Tasks[taskIdx];
int statusImpactValue =
Convert.ToInt32(task.GetField(UserSettings.Default.StatusImpact));
// Impacted task
if (statusImpactValue > 0)
{
MyTaskProcessing.HightlightCells(project, task,
(StatusImpactType)statusImpactValue);
}
}
public static void HightlightCells(MsProject.Project project,
MsProject.Task task, StatusImpactType impactType)
{
switch (impactType)
{
case StatusImpactType.LateMilestoneActivity:
MyTaskProcessing.FormatTaskCell(project, task,
Parameters.Fields.Finish, MsProject.PjColor.pjWhite,
MsProject.PjColor.pjBlue);
break;
case StatusImpactType.EarlyMilestone:
MyTaskProcessing.FormatTaskCell(project, task,
Parameters.Fields.Finish, MsProject.PjColor.pjWhite,
MsProject.PjColor.pjBlue);
break;
case StatusImpactType.ActivityDurationIncreased:
MyTaskProcessing.FormatTaskCell(project, task,
Parameters.Fields.Duration, MsProject.PjColor.pjWhite,
MsProject.PjColor.pjBlue);
break;
case StatusImpactType.PredecessorImpactTask:
MyTaskProcessing.FormatTaskCell(project, task,
Parameters.Fields.Predecessors, MsProject.PjColor.pjWhite,
MsProject.PjColor.pjBlue);
break;
case StatusImpactType.MilestoneActivityNeedStatus:
#region Determine % Complete
string percentCompleteString = String.Empty;
if (UserSettings.Default.UsePhysicalPercentComplete)
percentCompleteString =
Parameters.Fields.PhysicalPercentComplete;
else
percentCompleteString =
Parameters.Fields.PercentComplete;
#endregion
MyTaskProcessing.FormatTaskCell(project, task,
percentCompleteString, MsProject.PjColor.pjBlack, MsProject.PjColor.pjAqua);
MyTaskProcessing.FormatTaskCell(project, task,
Parameters.Fields.Finish, MsProject.PjColor.pjWhite,
MsProject.PjColor.pjBlue);
break;
case StatusImpactType.PredecessorDurationImpactTask:
MyTaskProcessing.FormatTaskCell(project, task,
Parameters.Fields.Duration, MsProject.PjColor.pjBlack,
MsProject.PjColor.pjAqua);
MyTaskProcessing.FormatTaskCell(project, task,
Parameters.Fields.Predecessors, MsProject.PjColor.pjBlack,
MsProject.PjColor.pjAqua);
break;
}
}
public static void FormatTaskCell(MsProject.Project project, MsProject.Task
task, string columnName, MsProject.PjColor cellColor, MsProject.PjColor
fontColor)
{
project.Application.SelectTaskField(task.ID, columnName, false,
0, 0, false, false);
project.Application.ActiveCell.CellColor = cellColor;
project.Application.ActiveCell.FontColor = fontColor;
}
Here's some sample code:
// Apply Status Impact View
ViewProcessing.Apply(project, Parameters.Views.vwStatusImpact);
// Select the entire sheet
project.Application.SelectSheet();
for (int taskIdx = 1; taskIdx <
project.Application.ActiveSelection.Tasks.Count; taskIdx++)
{
MsProject.Task task = project.Tasks[taskIdx];
int statusImpactValue =
Convert.ToInt32(task.GetField(UserSettings.Default.StatusImpact));
// Impacted task
if (statusImpactValue > 0)
{
MyTaskProcessing.HightlightCells(project, task,
(StatusImpactType)statusImpactValue);
}
}
public static void HightlightCells(MsProject.Project project,
MsProject.Task task, StatusImpactType impactType)
{
switch (impactType)
{
case StatusImpactType.LateMilestoneActivity:
MyTaskProcessing.FormatTaskCell(project, task,
Parameters.Fields.Finish, MsProject.PjColor.pjWhite,
MsProject.PjColor.pjBlue);
break;
case StatusImpactType.EarlyMilestone:
MyTaskProcessing.FormatTaskCell(project, task,
Parameters.Fields.Finish, MsProject.PjColor.pjWhite,
MsProject.PjColor.pjBlue);
break;
case StatusImpactType.ActivityDurationIncreased:
MyTaskProcessing.FormatTaskCell(project, task,
Parameters.Fields.Duration, MsProject.PjColor.pjWhite,
MsProject.PjColor.pjBlue);
break;
case StatusImpactType.PredecessorImpactTask:
MyTaskProcessing.FormatTaskCell(project, task,
Parameters.Fields.Predecessors, MsProject.PjColor.pjWhite,
MsProject.PjColor.pjBlue);
break;
case StatusImpactType.MilestoneActivityNeedStatus:
#region Determine % Complete
string percentCompleteString = String.Empty;
if (UserSettings.Default.UsePhysicalPercentComplete)
percentCompleteString =
Parameters.Fields.PhysicalPercentComplete;
else
percentCompleteString =
Parameters.Fields.PercentComplete;
#endregion
MyTaskProcessing.FormatTaskCell(project, task,
percentCompleteString, MsProject.PjColor.pjBlack, MsProject.PjColor.pjAqua);
MyTaskProcessing.FormatTaskCell(project, task,
Parameters.Fields.Finish, MsProject.PjColor.pjWhite,
MsProject.PjColor.pjBlue);
break;
case StatusImpactType.PredecessorDurationImpactTask:
MyTaskProcessing.FormatTaskCell(project, task,
Parameters.Fields.Duration, MsProject.PjColor.pjBlack,
MsProject.PjColor.pjAqua);
MyTaskProcessing.FormatTaskCell(project, task,
Parameters.Fields.Predecessors, MsProject.PjColor.pjBlack,
MsProject.PjColor.pjAqua);
break;
}
}
public static void FormatTaskCell(MsProject.Project project, MsProject.Task
task, string columnName, MsProject.PjColor cellColor, MsProject.PjColor
fontColor)
{
project.Application.SelectTaskField(task.ID, columnName, false,
0, 0, false, false);
project.Application.ActiveCell.CellColor = cellColor;
project.Application.ActiveCell.FontColor = fontColor;
}