This is additional info regarding my previous post: This is the code that
launches MS Project 2007. Is there a better, safer way to do this?
private void button1_Click(object sender, EventArgs e)
{
thermometer1.Value = 0;
tank1.Value = 0;
DateTime stDt = dateTimePicker3.Value;
string msProjectInstalled =
(string)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\12.0\\Project\\InstallRoot", "Path", "NF");
if ((msProjectInstalled == "NF") || (msProjectInstalled == null))
{
MessageBox.Show("This feature requires Microsoft Project
2007. Please install this application first.", "MARS MS Project Exception");
return;
}
ApplicationClass app = new ApplicationClass();
app.AppMaximize();
app.FileNew(Missing.Value, Missing.Value, Missing.Value,
Missing.Value);
bool r = false;
int i = 1;
string vName = "Text1";
string vValue = "test";
string status = "";
string message = "";
statusStrip1.Text = "Please stand by ... creating production
schedule.";
this.Refresh();
Project prj = app.ActiveProject;
app.GanttBarStyleEdit("1",
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
3,
Missing.Value,
1,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value,
Missing.Value
);
app.SelectTaskColumn("Duration", Missing.Value, Missing.Value,
Missing.Value);
app.TableEdit("&Entry", true, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, "Text2", "Part To Be Shipped", 12, 0, true,
true, 255, 1, 2, 1, Missing.Value, Missing.Value);
app.TableApply("&Entry");
app.TableEdit("&Entry", true, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, "Text3", "Customer Name", 22, 0, true, true,
255, 1, 2, 1, Missing.Value, Missing.Value);
app.TableApply("&Entry");
app.TableEdit("&Entry", true, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, "Text1", "Sales Document Number", 12, 0, true,
true, 255, 1, 2, 0, Missing.Value, Missing.Value);
app.TableApply("&Entry");
app.TableEdit("&Entry", true, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, "Text6", "Task or Operation", 65, 0, true,
true, 255, 1, 2, 1, Missing.Value, Missing.Value);
app.TableApply("&Entry");
//app.SelectTaskColumn("Start", Missing.Value, Missing.Value,
Missing.Value);
app.SelectTaskColumn("Predecessors", Missing.Value,
Missing.Value, Missing.Value);
app.TableEdit("&Entry", true, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, "Number2", "Accum. Total Per Job", 10, 2, true,
true, 255, 1, 8, 2, Missing.Value, Missing.Value);
app.TableApply("&Entry");
app.TableEdit("&Entry", true, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, "Number1", "Daily Production Quantity", 10, 2,
true, true, 255, 1, 8, 2, Missing.Value, Missing.Value);
app.TableApply("&Entry");
//app.SelectTaskColumn("Resource Names", Missing.Value,
Missing.Value, Missing.Value);
app.TableEdit("&Entry", true, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, "Flag1", "Scheduling Status", 10, 1, true,
true, 255, 1, 8, 1, Missing.Value, Missing.Value);
app.TableApply("&Entry");
//app.SelectTaskColumn("Predecessors", Missing.Value,
Missing.Value, Missing.Value);
app.TableEdit("&Entry", true, Missing.Value, Missing.Value,
Missing.Value, Missing.Value, "Date1", "Required Ship Date", 12, 1, true,
true, 255, 1, 8, 1, Missing.Value, Missing.Value);
app.TableApply("&Entry");
app.SelectTaskColumn("Predecessors", Missing.Value,
Missing.Value, Missing.Value);
app.ColumnDelete();
app.SelectTaskColumn("Resource Names", Missing.Value,
Missing.Value, Missing.Value);
app.ColumnDelete();
app.DisplayPlanningWizard = false;
app.DisplayProjectGuide = false;
app.SetSplitBar(14);
app.Visible = true;
app.ProjectSummaryInfo(Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value,
Missing.Value, stDt.ToShortDateString(), Missing.Value, Missing.Value,
Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
app.ViewApply("Resource Gr&aph", Missing.Value, Missing.Value);
app.FilePageSetupHeader(Missing.Value, PjAlignment.pjCenter,
"Fabricum Corporation \n Production Capacity Resource Graph");
app.FilePageSetupFooter(Missing.Value, PjAlignment.pjLeft,
"prepared by Greg Frazier");
app.ViewApply("&Gantt Chart", Missing.Value, Missing.Value);
app.CustomFieldSetFormula(PjCustomField.pjCustomTaskFlag1,
"iif([Finish]>=[Date1],\"Yes\",\"No\")");
app.CustomFieldProperties(PjCustomField.pjCustomTaskFlag1,
PjCustomFieldAttribute.pjFieldAttributeFormula, PjSummaryCalc.pjCalcNone,
false, false);
/* CustomFieldIndicators FieldID:=pjCustomTaskFlag1,
SummaryInheritsNonsummary:=True, ProjectInheritsSummary:=True,
ShowToolTips:=True
CustomFieldIndicatorAdd FieldID:=pjCustomTaskFlag1,
Test:=pjCompareEquals, Value:="Yes", IndicatorID:=pjIndicatorFaceSadRed
CustomFieldProperties FieldID:=pjCustomTaskFlag1,
Attribute:=pjFieldAttributeFormula, SummaryCalc:=pjCalcNone,
GraphicalIndicators:=True, Required:=False */
app.CustomFieldIndicators(PjCustomField.pjCustomTaskFlag1, true,
true, true);
app.CustomFieldIndicatorAdd(PjCustomField.pjCustomTaskFlag1,
PjComparison.pjCompareEquals, "Yes", PjIndicator.pjIndicatorFaceSadRed,
PjCriteriaList.pjCriteriaNonSummary, Missing.Value);
app.CustomFieldProperties(PjCustomField.pjCustomTaskFlag1,
PjCustomFieldAttribute.pjFieldAttributeFormula, PjSummaryCalc.pjCalcNone,
true, false);
app.SetTitleRowHeight(6);
this.loadMSProjectSchedule(ref app, out status, out message);
if (status == "Abort")
{
statusStrip1.Text = "Process aborted!";
return;
}
this.levelTasks();
app.SelectTaskColumn("Name", Missing.Value, Missing.Value,
Missing.Value); // can't get this to work
app.ColumnDelete();
app.SelectCell(1, 2, 0);
statusStrip1.Text = "All done!";
}
If so, please provide examples.
Thanks.
Greg