There have been a few posts on the newsgroups about automating MS Project from Excel, so I thought a simple example might be in order. This example takes task information from a spreadsheet and creates tasks in a project. The worksheet looks like this:
This macro opens a Project and loops through cells, adding Tasks along the way.
Dim prjApp As MSProject.Application
Dim prjProject As MSProject.Project
Dim prjTask As MSProject.Task
Dim rCell As Range
Set prjApp = New MSProject.Application
Set prjProject = prjApp.ActiveProject
For Each rCell In Sheet1.Range(“A2:A6?).Cells
Set prjTask = prjProject.Tasks.Add(rCell.Value)
.Start = rCell.Offset(0, 1).Value
.Duration = rCell.Offset(0, 2).Value
The resulting project looks like this:
By the way, what’s the deal with the FileOpen method? Is Projects.Open too complicated? I think I need to post a scathing rant of other object models and how they should be more like Excel.