0

In a .NET application I am using Microsoft.Office.Interop.MSProject library to automate and write data to an Ms-Project .Mpp file. There are thousands of tasks and resource assignments that should be created and it takes very long to create them by using methods like Assignments.Add, like 10s of minutes in total.

In the below link, there is a very similar problem and the answer mentions that the fastest way to import data to an MS-Project file is to create a map and use "Project Import Wizard". After the answer adds Automating the Wizard is another subject and requires another question, so this is that question; If I create a map and create the data on an Excel or CSV file, how can I automate Project Import Wizard so it imports the data from that file by using a specific map without manual user interference. How to Improve Performance when Loading Data into Microsoft Project with VSTO

EDIT : enter image description here

1 Answers1

1

As long as the map is stored in the global.mpt file, automating the import wizard to create a new project schedule is as simple as using the FileOpenEx method with the map argument. Here is a snipet to get you started; adapt as necessary:

MSProject.Application projectApplication = new MSProject.Application();
object missingValue = System.Reflection.Missing.Value;

projectApplication.FileOpenEx("<your file name here>", false, PjMergeType.pjDoNotMerge,
            missingValue, missingValue, missingValue, missingValue, missingValue,
            missingValue, missingValue, "<your map name here>", 
            PjPoolOpen.pjPoolReadOnly, missingValue, missingValue,
            missingValue, missingValue, missingValue);

Note: if using the FileOpenEx method to merge data into the active file, be sure the map is in that file. Use the OrganizerMoveItem method if necessary.

Rachel Hettinger
  • 7,927
  • 2
  • 21
  • 31
  • Thank you Rachel for the reply, I have edited the question to include FileOpenEx parameters, so the data to be imported is in an Excel file, where should this Excel file name (including path) will go to? – bbb android Aug 23 '21 at 15:08
  • The file name, including path, is the first argument of the FileOpenEx method. – Rachel Hettinger Aug 23 '21 at 15:14
  • Ok I think now I get it, I thought that file name would be the Ms. Project file name, so it will be the Excel filename right? – bbb android Aug 23 '21 at 15:16
  • If the map is defined as creating a new file, the FileOpenEx will import the data into a new Project (eg "Project1"). If the map is defined to merge data into an existing file, it will merge into the active project. Either way, you don't need to supply the name of a Project file. – Rachel Hettinger Aug 23 '21 at 17:49