Insert SubProject

C

Chris Molland

Hello,

I am really struggling to write the VB code to insert a subproject into a
project file.

I am using the following:

'Insert the Task from the library.
oProjApp.ConsolidateProjects( _
Filenames:=task_path, _
NewWindow:=False, _
AttachToSources:=False, _
HideSubtasks:=True)

I keep getting a warning message "Do you want to save changes to "filename"?
referring to the MS Project file which I want to insert.

I had hoped that by setting "AttachToSources" to False the inserted
subproject would be completely divorced from the source file.

I simply want to insert the referenced MS Project file as a Subproject after
any previous tasks, be they Tasks or subprojects.

I hope someone can help.

Regards
 
J

John

Chris Molland said:
Hello,

I am really struggling to write the VB code to insert a subproject into a
project file.

I am using the following:

'Insert the Task from the library.
oProjApp.ConsolidateProjects( _
Filenames:=task_path, _
NewWindow:=False, _
AttachToSources:=False, _
HideSubtasks:=True)

I keep getting a warning message "Do you want to save changes to "filename"?
referring to the MS Project file which I want to insert.

I had hoped that by setting "AttachToSources" to False the inserted
subproject would be completely divorced from the source file.

I simply want to insert the referenced MS Project file as a Subproject after
any previous tasks, be they Tasks or subprojects.

I hope someone can help.

Regards

Chris,
You will get that warning because the default insertion is dynamic (i.e.
linked subproject). When you set the AttachToSource argument as false,
you are effectively telling Project to break the link, so it asks you if
you want to save the change (i.e. break the link). Since you're breaking
the link immediately on consolidation, it probably doesn't matter if you
answer "yes" or "no" to the warning. The warning can be suppressed with
the resulting action by Project being that it will save the changes.

Hope this helps.
John
Project MVP
 
C

Chris Molland

Hello John,

Thanks for your clear and prompt reply. You suggest that Project can
suppress the warning - can you please explain how this is done?

I want to create a library of projects, each with their own Tasks all
pre-defined. The idea is that users select from the library items, using a
Visual Basic wizard I have developed, and they are inserted into a new
"master" project without the users needing to use Project.

In practice though I have had the problem which you explained (I will have
to suppress the warning somehow) along with another warning because the dates
in the library files are inevitably before the new "master" project start
date. I want the library items to pre-define tasks, predecessors and
durations. However I want the start date for a library item to be defined
using the wizard on inserting the library project file.

Do you have any suggestions.

Happy Christmas

Chris
 
J

John

Chris Molland said:
Hello John,

Thanks for your clear and prompt reply. You suggest that Project can
suppress the warning - can you please explain how this is done?

I want to create a library of projects, each with their own Tasks all
pre-defined. The idea is that users select from the library items, using a
Visual Basic wizard I have developed, and they are inserted into a new
"master" project without the users needing to use Project.

In practice though I have had the problem which you explained (I will have
to suppress the warning somehow) along with another warning because the dates
in the library files are inevitably before the new "master" project start
date. I want the library items to pre-define tasks, predecessors and
durations. However I want the start date for a library item to be defined
using the wizard on inserting the library project file.

Do you have any suggestions.

Happy Christmas

Chris

Chris,
Suppress the warning using,
DisplayAlerts = False

Why don't you just create template files instead of using the
consolidation process? It seems like you are doing it the hard way. And
your sentence about users not needing to use Project won't play. Users
certainly will have to use Project to run the macro or open a file.

I don't remember if the DisplayAlerts Property will suppress the warning
about the start date. If it doesn't, you can use code to either set the
start date of the master to an arbitrary date in the past and then
update it after creating the new file, or do what I did in one of my
macros, read the start date of each subproject to be inserted and then
set the start date of the master to the earliest start date.

John
Project MVP
 
C

Chris Molland

Hello John,

Thank you for the code to suppress the warning. I can't see how I would use
a template file. I have written a VB application which looks in a Library
folder and gives the user a pop-down (combobox) list of pre-defined
sub-projects. MS Project is running in another window. A new MS Project (2007
Pro) file is created and then I want the user to work through the wizard
entering Start datetime/predecessor select a sub-project from the library and
click Enter. The sub-project would then be programatically added into the MS
Project file. The user repeats the process building up a master project by
defining the sequence of many pre-defined subprojects.

How may I use template files to avoid consolidating project files? I would
certainly welcome an easier method!

Adding the new subproject into the master file after the last subproject, or
single Task which the user is free to add manually, seems difficult. Do I
have to somehow work out where the last row is and Select the next row before
adding the new subproject?

Many thanks for your wise words.
 
J

John

Chris Molland said:
Hello John,

Thank you for the code to suppress the warning. I can't see how I would use
a template file. I have written a VB application which looks in a Library
folder and gives the user a pop-down (combobox) list of pre-defined
sub-projects. MS Project is running in another window. A new MS Project (2007
Pro) file is created and then I want the user to work through the wizard
entering Start datetime/predecessor select a sub-project from the library and
click Enter. The sub-project would then be programatically added into the MS
Project file. The user repeats the process building up a master project by
defining the sequence of many pre-defined subprojects.

How may I use template files to avoid consolidating project files? I would
certainly welcome an easier method!

Adding the new subproject into the master file after the last subproject, or
single Task which the user is free to add manually, seems difficult. Do I
have to somehow work out where the last row is and Select the next row before
adding the new subproject?

Many thanks for your wise words.

Chris,
It wasn't clear to me from your previous posts that users pick more than
one complete subproject to build a new project. I assumed they were just
picking a single file that had the basics they needed and then go from
there. That's why I suggested using a series of template files - each
one being a fully set up project. You could still use templates, (and
that's basically what your subproject files are), but yes, the users
would still need to consolidate.

There are various ways to build up a consolidate a master file so I
can't say what the best way is for your needs. However, one way to avoid
the issue of where each file is inserted is to first select all
subprojects and then consolidate them as a group. Add the new
user-defined tasks after the new file has been built.

John
Project MVP
 
C

Chris Molland

Thanks John,

My users will be inserting between 20 to 50 sub-projects into a new MS
Project (master) file. Each time running through the wizard I have developed
which gathers information, refers to an SQL engineering database to ensure
the validity of their answers and eventually presenting s selection of items
from the library of sub-projects to choose from. You're correct in that the
library sub-projects are like templates. I noticed however that you can't
insert a Template file.

Having inserted a sub-project into a file, suppressing any warnings as you
sugested, I then want to set the Start datetime and any predecessors which
the user has selected in the wizard. How do I ensure the new sub-project is
inserted in the next empty row (do I sort the tasks before inserting) and how
do I refer to the newly inserted sub-project to set any values such as Start.
Do I have to loop through all of the sub-projects looking for the highest ID
(surely not!). Once I have located the newly inserted sub-project I presume I
could read the GUID to refer to it directly for any other values I want to
set?

I appreciate your help over this festive period. Purely out of curiosity
where in the world are you?

Regards
 
J

John

Chris Molland said:
Thanks John,

My users will be inserting between 20 to 50 sub-projects into a new MS
Project (master) file. Each time running through the wizard I have developed
which gathers information, refers to an SQL engineering database to ensure
the validity of their answers and eventually presenting s selection of items
from the library of sub-projects to choose from. You're correct in that the
library sub-projects are like templates. I noticed however that you can't
insert a Template file.

Having inserted a sub-project into a file, suppressing any warnings as you
sugested, I then want to set the Start datetime and any predecessors which
the user has selected in the wizard. How do I ensure the new sub-project is
inserted in the next empty row (do I sort the tasks before inserting) and how
do I refer to the newly inserted sub-project to set any values such as Start.
Do I have to loop through all of the sub-projects looking for the highest ID
(surely not!). Once I have located the newly inserted sub-project I presume I
could read the GUID to refer to it directly for any other values I want to
set?

I appreciate your help over this festive period. Purely out of curiosity
where in the world are you?

Regards

Chris,
I'll answer your last question first. I'm with Carmen San Diego. . . :)

It sounds like your "subprojects" are really just short groups of tasks
and not really "projects". Do I take it that for some reason the user
can't select all desired subprojects before consolidating? And what
exactly does sorting have to do with it?

Once a subproject is inserted and unlinked, it no longer has any
identifier in the new project - it does retain its old ID sequence but
the ID values are determined by the new project file. The same is true
with the Unique ID. The GUID is totally new

If you want a sure fire way to track tasks or even subprojects when they
are inserted and unlinked into a new project, I suggest you set up your
own code identifier. For example, let's say that one of your subprojects
is a set of tasks that delineates a survey of vendors and another
subproject is a set of tasks that delineates mechanical design. You
might designate spare task Text1 as the subproject identifier and give
the vendor tasks a code identifier of VS-[unique ID] and the mechanical
design tasks a code identifier of MD-[unique ID]. Those identifiers will
stay with the tasks even when the respective subprojects are inserted
into a new project file.

John
Project MVP
 
C

Chris Molland

Hello John,

You are quite correct my sub-projects are small collections of Tasks which
have been pre-defined and stored. This allows the Manager to define them once
and ensure consistency when used.

The user of my VB application clicks a button "Add Task" and a Wizard
appears. They enter a Start date/time or select a predecessor (list of
Sub-Project names currently inserted) and then select different engineering
options from pop-down lists on each page of the Wizard. The Wizard is looking
up data from a SQL database based upon each user selection and supplying
refined options for the next screen. Eventually the user is presented with a
small selection of Library sub-projects based upon all of their previous
selections. The user selects one and it has to be added to the Master
Project. The user can then repeat the process entering different values into
the Wizard to eventually select the next sub-project to insert.

I simply want to insert these sub-projects into the MS Project file, set the
Start date/time to the value which the user entered or set a predecessor if
the user selected one.

The user may insert the same sub-project more than once so I want to insert
the sub-project and then establish which item in the master project file the
new sub-project is so that I can set its Start date/time and predecessor.

To summarise, I would like to programatically:

1. Insert a MS Project file (by specifying the path) into the ActiveProject
with no link to the source file. I don't want any warnings to interfere with
the process. This includes a warning that the sub-project Start is
(inevitably) before the ActiveProject Start. Could I set the ActiveProject
Start to an early date and then set it back after the insert process is
complete?
2. Get the GUID for the sub-project just inserted so that I can change some
values (Start, Predecessor).
3. Set the Start date/time or predecessor values for the new sub-project.

I appreciate your patience on this matter.

Regards
 
J

John

Chris Molland said:
Hello John,

You are quite correct my sub-projects are small collections of Tasks which
have been pre-defined and stored. This allows the Manager to define them once
and ensure consistency when used.

The user of my VB application clicks a button "Add Task" and a Wizard
appears. They enter a Start date/time or select a predecessor (list of
Sub-Project names currently inserted) and then select different engineering
options from pop-down lists on each page of the Wizard. The Wizard is looking
up data from a SQL database based upon each user selection and supplying
refined options for the next screen. Eventually the user is presented with a
small selection of Library sub-projects based upon all of their previous
selections. The user selects one and it has to be added to the Master
Project. The user can then repeat the process entering different values into
the Wizard to eventually select the next sub-project to insert.

I simply want to insert these sub-projects into the MS Project file, set the
Start date/time to the value which the user entered or set a predecessor if
the user selected one.

The user may insert the same sub-project more than once so I want to insert
the sub-project and then establish which item in the master project file the
new sub-project is so that I can set its Start date/time and predecessor.

To summarise, I would like to programatically:

1. Insert a MS Project file (by specifying the path) into the ActiveProject
with no link to the source file. I don't want any warnings to interfere with
the process. This includes a warning that the sub-project Start is
(inevitably) before the ActiveProject Start. Could I set the ActiveProject
Start to an early date and then set it back after the insert process is
complete?
2. Get the GUID for the sub-project just inserted so that I can change some
values (Start, Predecessor).
3. Set the Start date/time or predecessor values for the new sub-project.

I appreciate your patience on this matter.

Regards

Chris,
It sounds like quite an elaborate procedure you have. Let me answer your
questions again although I think I've answered them already.
1. We already talked about how to suppress the warning messages, however
if the DisplayAlerts = false doesn't suppress the start date warning,
then yes I would set the active project date to a date that you know
will be earlier than any subproject. You can always reset the start date
after the whole new Project file is populated.
2. I already told you that the GUID is useless for what you are doing.
Instead, use the method I suggested in my last post.
3. This doesn't look like a question, so I'll just say, "yeah, do that".

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