While blogging across social technet forum, i came to a question wherein a user didn’t wanted to use PSI (and infact there isn’t any way to save a file as “template” to project server using PSI or atleast i haven’t seen one)
Though the standard practice is to deploy MPT templates using MS Project itself, there isn’t any PSI for automating the same or at least i couldn’t find any documentation anywhere, someone else might want to comment, please feel free,
and since template deployment doesn’t happens very often, or i would say it’s not a very frequent process it doesn’t makes sense to have a code developed for it, however user’s client wanted it to be done using C# / .NET so he started exploring the opporutnities of using MS Project Interop Assembly, curiosly I started coding for the same and here is what I came up with try it, Viola its working J
Add Microsoft.Office.Interop.MSProject Assembly reference to your C# Project you can find it under COM tab
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.MSProject;
using System.Reflection;
namespace RnDProject
{
public partial class InteropInvoke : Form
{
public InteropInvoke()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string fileLoc = @”C:\sunil\Test Development Plan.mpp”;
ApplicationClass ProjectApp = new ApplicationClass();
// Open the file. There are a number of options in this
// constructor as you can see
ProjectApp.FileOpen(fileLoc, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, PjPoolOpen.pjDoNotOpenPool, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
ProjectApp.FileSaveAs(“<>\\CurrencyTest12”, PjFileFormat.pjMPT, Type.Missing, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, true, true, true, true, Type.Missing, true);
// Get the active project
Project proj = ProjectApp.ActiveProject;
}
catch (System.Exception Ex)
{
//catch Exception here to determine if file exists 🙂
}
}
}
}
Is there any way to create plan directly from Excels using Interop assembly .
I think,we can only do with template..
I believe you can, but it should be executed in a different flow, like open MS Project Connect, Execute the VBA Macro which reads from Excel sheet pull all tasks and everything >> add it to MS Project >> Save >> Publish
This way you don’t need to actually launch MS Project From Excel rather from MS Project itself you are reading Excel, Does this makes sense ?
Just looked upon and guess what, this is what i did and it works perfectly fine, add Micorosft Project 12.0 Library in Tools >> Reference and run the code viola, all set and since i can one task so can i read the excel and create as many as i want
Sub test()
Dim pjApp As MSProject.Application
Set pjApp = New MSProject.Application
pjApp.Visible = True
pjApp.FileOpen “Clocks.mpp”
pjApp.ActiveProject.Tasks.Add “Wind clocks”
pjApp.FileSave
pjApp.FileClose
pjApp.Quit
End Sub
Hello Sunil,
Your code is great. I just want to know how were you able to open microsoft project in connected mode? Whenever I open microsoft project using the interop library, it opens in local mode without being connected to a project server. I wasn’t able to locate a code to connect project client to project server. Do you have idea of how can this be done?
Thanks,
George
Hi George
Which code are you talking of ? the one in the main post or the one shared in the comment, for launching MS Project from within Excel
Now for the code in main post, i open up the MS Project in connected mode and then execute the code and it works fine,
But for launching the code from excel, i haven’t tested let me have a look and get back if i figure out something on this