Open MS Project From Excel & read Task Properties List

G

Guest

I want to open a MS Project file and create a list of the Task table field
names. (e.g. ID, Name, Start, Finish, etc.) I want the complete list of field
names to populate to an Excel worksheet.

I am looking for code to do two things:

1: List the Task table field names from the task collection

2: Possibly open the MS project file without having a copy of MS project open.

Thanks in advance.
 
C

Colby Africa

Hello,

A great place to start is the Project SDK. Here is an article on the
Tasks collection:

http://msdn2.microsoft.com/en-us/library/bb214628.aspx

Opening an MPP from Excel is fairly straightforward. Reference the
Project type library first.

Dim projectApplication As New MSProject.Application

projectApplication.FileOpenEx "C:\data\temp\project.mpp"

Dim taskItem As Task

For Each taskItem In projectApplication.ActiveProject.Tasks

Debug.Print taskItem.Name

Next

Hope this helps!

Colby Africa
http://colbyafrica.blogspot.com
 
G

Guest

Colby,

How do you access the list of field names in the task table? (not the tasks
themselves.)
 
C

Colby Africa

Oops, let's see. Something like this:

Dim projectApplication As New MSProject.Application

projectApplication.FileOpenEx "C:\data\temp\project.mpp"


Dim field As tableField

For Each field In
projectApplication.ActiveProject.TaskTables(projectApplication.ActiveProject.CurrentTable).TableFields
Debug.Print field.Title
Next

Is that what you are looking for?

Colby
 
G

Guest

Seems close.



I get lots of blanks for titles and I am not sure if it is giving me the
same list as the enums that you get from taskItem.Name in your last post.

What I want is the same list that pops up when you type taskitem and the
period. I just want to loop through and I will send it off to an array.

Thanks again
 
C

Colby Africa

Got it:

Dim projectApplication As New MSProject.Application

projectApplication.FileOpenEx "C:\data\temp\project.mpp"

Dim field As TableField

For Each field In
projectApplication.ActiveProject.TaskTables(projectApplication.ActiveProject.CurrentTable).TableFields
Debug.Print FieldConstantToFieldName(field.field)
Next

I was missing the call out to FieldConstantToFieldName

Colby
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top