The Code is as follows:
Using System; using System. collections. generic; using System. text; using Microsoft. office. interop. MSProject; namespace ConsoleApplication {class Program {static void Main (string [] args) {Program pro = new Program (); pro. readMpp (); // pro. callMacro (); // pro. createMpp ();} // call the macro public void callMacro () {Object missing = Type defined in mpp. missing; ApplicationClass prj = new ApplicationClass (); // open the mpp file prj. fileOpen ("C:/Documents ents and Settings/Administrator/My Documents ents/test. mpp ", false, missing, PjPoolOpen. pjPoolReadWrite, missing, and missing); // The call name is testMacro prj. macro ("testMacro"); // close, but do not save mpp prj. fileClose (PjSaveType. pjDoNotSave, false); prj. quit (PjSaveType. pjDoNotSave);} public void readMpp () {Object missing = Type. missing; ApplicationClass prj = new ApplicationClass (); prj. fileOpen ("D:/test. mpp ", false, missing, PjPoolOpen. pjPoolReadWrite, missing, missing); foreach (Project proj in prj. projects) {foreach (Task task in proj. tasks) {System. console. writeLine ("|" + task. name + "|" + task. uniqueID + "|" + task. resourceNames + "|") ;}} prj. fileClose (PjSaveType. pjSave, false); prj. quit (PjSaveType. pjSave); System. console. read ();} public void createMpp () {Object missing = Type. missing; ApplicationClass prj = new ApplicationClass (); PjFileFormat format = PjFileFormat. pjMPP; // format defines prj. visible = true; prj. fileNew (Type. missing, Type. missing, Type. missing, false); Project myProject = prj. activeProject; Task task = null; task = myProject. tasks. add ("zhi", 1); task. start = "2008-8-1"; task. finish = "2008-8-18"; task. setField (PjField. pjTaskNotes, "Task1"); task = null; task = myProject. tasks. add ("wenzhixing", 2); task. start = "2008-8-8"; task. finish = "2008-8-28"; task. actualStart = ""; task. actualFinish = ""; task. outlineLevel = 2; task. setField (PjField. pjTaskResourceNames, "wenzhi"); task = null; task = myProject. tasks. add ("wen", 3); task. start = "2008-8-11"; task. finish = "2008-8-18"; task. setField (PjField. pjTaskNotes, "Task2"); task. notes + = "hehe"; task. outlineLevel = 1; task = null; task = myProject. tasks. add ("wen", 4); task. start = "2008-8-18"; task. finish = "2008-8-28"; task. outlineLevel = 2; task. setField (PjField. pjTaskResourceNames, "wenzhi"); prj. fileSaveAs ("C:/Documents and Settings/Administrator/My Documents/mjm. mpp ", format, missing, false, missing, PjPoolOpen. pjPoolReadWrite, missing, missing );}}}