Microsoft Office Tutorials and References
In Depth Information
Creating a Project and adding a task dynamically
Let's see an example of how to create a new project and add a task item to it, by
using the VSTO objects available for Microsoft Project.
Open Visual Studio 2008, to create a new Project solution, as described earlier. Write
the following code in the ThisAddIn.cs file:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// Using project object to create new project document
MSProject.Project PacktProject = Application.Projects.Add(false,
Type.Missing, false);
// Set the Name for project
PacktProject.Name = "New Book for Packt";
// Add the project manager
PacktProject.Manager = "Radhika";
// Get the active project
PacktProject = Globals.ThisAddIn.Application.ActiveProject;
// Add the task to the active project
PacktProject.Tasks.Add("Prepare Topic", Type.Missing);
}
The results of executing this code can be seen in the following screenshot:
 
Search JabSto ::




Custom Search