Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I added office 2010 MS project in my solution and below code is generated, how can I call this code on button click
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using MSProject = Microsoft.Office.Interop.MSProject;
using Office = Microsoft.Office.Core;

namespace FirstProjectAddIn
{
    public partial class ThisAddIn
    {

      public   void Application_NewProject(Microsoft.Office.Interop.MSProject.Project pj)
        {
            MSProject.Task newTask = pj.Tasks.Add
                ("This text was added by using code", missing);
            newTask.Start = DateTime.Now;
            newTask.Duration = "3";
            newTask.ResourceNames = "MAnoj, Kelly Krout";
        }

        public  void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
           // this.Application.NewProject += new Microsoft.Office.Interop.MSProject._EProjectApp2_NewProjectEventHandler(Application_NewProject);

        }

        public void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }

        #region VSTO generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
        
        #endregion
    }
}
Posted
Updated 14-Nov-12 23:41pm
v2

1 solution

Try something like this.
C#
//...
    FirstProjectAddIn.ThisAddIn addin = new FirstProjectAddIn.ThisAddIn();
    Microsoft.Office.Interop.MSProject.Application prj_app = new Microsoft.Office.Interop.MSProject.ApplicationClass();
    if (prj_app != null){
        prj_app.Visible = false; // Make MS Project application invisible
        // ... create new or load existing project
        Microsoft.Office.Interop.MSProject.Project p = new Microsoft.Office.Interop.MSProject.Project();
        addin.Application_NewProject(p);
        //...
        // exiting app
        prj_app.Quit(Microsoft.Office.Interop.MSProject.PjSaveType.pjSave);
    }
//...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900