Click here to Skip to main content
13,093,097 members (80,526 online)
Rate this:
Please Sign up or sign in to vote.
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
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);
Posted 14-Nov-12 23:33pm
Updated 14-Nov-12 23:41pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try something like this.
    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();
        // exiting app

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.170813.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100