Insert A Project

C

Chris Molland

Hello,

Following some great advise from John I can now programatically insert a MS
Project file successfully. However I can't seem to control where it is placed.

My users are able to freely use project 2007 to adjust values, print reports
etc. To insert a Project they click on my Visual Basic application which
guides them through a selection process and eventually inserts the
pre-defined MS Project file.

Of course they may have been at any View, have any cell selected or
collapse/expand any previous sub-projects.

I simply want to insert the new MS Project file at the next available row
and then adjust some of its values. However when I run my code the inserted
sub-project is positioned on any row which happens to be selected and any
previous rows seem to be assigned ID values, like ghost Tasks.

I can see how to switch to Gantt view but not how to insert in the next row.

Once inserted, how can I change the Start date/time for the first Task in
the sub-project. John helpfully suggested I create a UniqueID in one of the
Custom Fields to reference which would work fine except the same MS Project
file may be inserted several times and of course they would have the same
value. Would I have to loop through all of the sub-projects looking for the
highest UniqueID value?

Thank you.
 
J

Jan De Messemaeker

Hi,

Use this sequence:

Viewapply "Gantt Chartt'
filterapply "All Tasks"
Outlineshowalltasks
activeproject.tasks.add
selectend
consolidateprojects ....
selectend
activeselection.tasks(1).delete

hope this helps,

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
 
J

John

Chris Molland said:
Hello,

Following some great advise from John I can now programatically insert a MS
Project file successfully. However I can't seem to control where it is placed.

My users are able to freely use project 2007 to adjust values, print reports
etc. To insert a Project they click on my Visual Basic application which
guides them through a selection process and eventually inserts the
pre-defined MS Project file.

Of course they may have been at any View, have any cell selected or
collapse/expand any previous sub-projects.

I simply want to insert the new MS Project file at the next available row
and then adjust some of its values. However when I run my code the inserted
sub-project is positioned on any row which happens to be selected and any
previous rows seem to be assigned ID values, like ghost Tasks.

I can see how to switch to Gantt view but not how to insert in the next row.

Once inserted, how can I change the Start date/time for the first Task in
the sub-project. John helpfully suggested I create a UniqueID in one of the
Custom Fields to reference which would work fine except the same MS Project
file may be inserted several times and of course they would have the same
value. Would I have to loop through all of the sub-projects looking for the
highest UniqueID value?

Thank you.

Chris,
I'm glad to see you're getting there.

Let me provide a little tweak to Jan's code. As written it won't quite
do what you want (i.e. it will insert the new project in the outline of
the previous task in the master instead of as a new subproject after the
last subproject). I've also added a few lines to set the start date (you
can add the time if you wish).

Sub ConsolidateProjs()
Dim mstr As String, filnam As String
OptionsSchedule schedulemessages:=False, StartOnCurrentDate:=False
ViewApply "Gantt Chart"
FilterApply "All Tasks"
mstr = ActiveProject.Name
SelectAll
OutlineHideSubTasks
ActiveProject.Tasks.Add
SelectEnd
FileOpen Name:=[your file]
filnam = ActiveProject.Name
ActiveProject.ProjectStart = "12/1/07"
Application.Projects(mstr).Activate
DisplayAlerts = False
ConsolidateProjects FileNames:=[your file], NewWindow:=False, _
attachtosources:=False, hidesubtasks:=False
OutlineHideSubTasks
SelectEnd
ActiveSelection.Tasks(1).Delete
Application.Projects(filnam).Activate
FileClose Save:=pjDoNotSave
End Sub

Hope this helps.
John
Project MVP
 
C

Chris Molland

Thank you both very much,

I have just read your replies and am very grateful for the advice. I will
try the code out later today and let you know how I get on.

Regards
 
C

Chris Molland

Happy New Year John,

Well it all worked really well thank you.

I did find that after setting the Start date of the Library Project file,
prior to the consolidation, the date was ignored when inserted. I don't know
if you found this.

All of my Library Project files have a "Start" milestone as the first Task.
I used the following code to set this just before switching back to the
Master Project file and consolidating:

oProjApp.ActiveProject.Tasks.Item(1).Start = start_datetime

This seems to work well.

I then relied upon the new sub-project being the last item in the Master
Project file so I used a SelectEnd after your suggested code to then set the
Summary Task fields I wanted:

'Select the Last Task which will be the new Task.
oProjApp.SelectEnd()

'Set the DeviceId.
oProjApp.ActiveSelection.Tasks(1).Number1 = device_id

This too seems to work well.

I'll carry on with other aspects of the project now. Thanks again for your
support.

Regards
 
J

John

Chris Molland said:
Happy New Year John,

Well it all worked really well thank you.

I did find that after setting the Start date of the Library Project file,
prior to the consolidation, the date was ignored when inserted. I don't know
if you found this.

All of my Library Project files have a "Start" milestone as the first Task.
I used the following code to set this just before switching back to the
Master Project file and consolidating:

oProjApp.ActiveProject.Tasks.Item(1).Start = start_datetime

This seems to work well.

I then relied upon the new sub-project being the last item in the Master
Project file so I used a SelectEnd after your suggested code to then set the
Summary Task fields I wanted:

'Select the Last Task which will be the new Task.
oProjApp.SelectEnd()

'Set the DeviceId.
oProjApp.ActiveSelection.Tasks(1).Number1 = device_id

This too seems to work well.

I'll carry on with other aspects of the project now. Thanks again for your
support.

Regards

Chris,
I'm glad to hear that it's coming together for you, so you're welcome
and thanks for the feedback.

The project start date of the subproject will be ignored if any tasks in
the subproject have a constraint (i.e. not "as-soon-as-possible"). I
found this out while I was developing and testing the code I posted. It
sounds like your start milestone may have a constraint. However if you
use code to specifically set the start date/time of the first
performance task in the subproject, in lieu of setting the subproject's
project start date, (as you apparently are doing), that will also do the
trick.

It's been fun and happy New Year to you also.

John
Project MVP
 

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