Process multiple Projects

J

JimS

I am a veteran Access vba programmer, and I've written some Project vba. I
need a pointer to get started on my current assignment.

I have added a form to a project ("A4BB") which contains predecessors for
tasks in a dozen other projects. I want to link them automatically. The users
in those projects have identified the predecessor by putting a unique "key"
in Text1, which I will match to that same unique "key" in A4BB. The form asks
for a "repository" location, then asks for the user to select the one or more
projects they want processed.

I rifle through a list box in the form with the project names. Once I've got
the project name, I need to open it, find all the incidents of tasks with
Text1 containing a valid "key", then link that task back to its predecessor
task in A4BB.

Strategy? I don't need detailed instructions, just a strategy for
proceeding. I'm using MSP2007 on MSP2003 files. There must be something like
an "open" method, but I can't seem to find it in the project object model. I
can see how you enumerate the projects collection, but how to open an
additional project and then link tasks still eludes me.

Thanks folks!
 
J

Jack Dahlgren MVP

Pass the file path to the FileOpen method (Proj 2003) or FileOpenEx method
(2007). Here is an example which sets Proj1 as the current Project file, and
Proj2 as the new file. Then it writes the names of both of them. Just make
sure you know which project is which and you can read and write to/from
either one of them,


Sub openNewProj()
Dim Proj1 As Project
Dim Proj2 As Project
Set Proj1 = ActiveProject
FileOpen Name:="C:\MyProjectFile.mpp", ReadOnly:=False
Set Proj2 = ActiveProject
MsgBox Proj1.Name
MsgBox Proj2.Name
End Sub

-Jack Dahlgren
 
J

JimS

Jack,
Thank you so much. After much research and your help, I've accomplished
much. I have some issues if you'll indulge me:

1. I was stepping through the task collection (for each...) on one of the
projects when somehow I ended up with a "nothing" task. I can't see how I
could be out of bounds (of course, I'm a perfect programmer -- lol.) Any
other way that could happen?

2. When I set interproject relationships (taskdependencies...), those
relationships show up as 'grayed-out' tasks in their respective projects. Is
that normal? Required?

3. I tried to delete one of the dependencies manually, but every time I
tried, I got a message saying it would foul up the schedule because of
another constraint. Now each of the task successors is constrained (SNE), but
so what? Why would that be an issue, since I just put this new dependency in,
why wouldn't it go right back to where it was?

4. I realize now I might try to add the same dependency twice unless I
guard against it. Will that be an issue? Will it error out, or just ignore
the duplication?

Again, Jack, I appreciate your help! Thanks!
 
J

JimS

One other item, if I could. For each task in the subproject, I loop through
every task in the master project ('a4bb') looking for a match. It'd be much
better if I could go through them sorted, or perhaps filtered. Can I sort the
main project task collection before running through it? Or do I have to
filter it and loop through the filtered task list (not a collection?) until I
find the right match or run past it?

Strategy?
--
Jim


JimS said:
Jack,
Thank you so much. After much research and your help, I've accomplished
much. I have some issues if you'll indulge me:

1. I was stepping through the task collection (for each...) on one of the
projects when somehow I ended up with a "nothing" task. I can't see how I
could be out of bounds (of course, I'm a perfect programmer -- lol.) Any
other way that could happen?

2. When I set interproject relationships (taskdependencies...), those
relationships show up as 'grayed-out' tasks in their respective projects. Is
that normal? Required?

3. I tried to delete one of the dependencies manually, but every time I
tried, I got a message saying it would foul up the schedule because of
another constraint. Now each of the task successors is constrained (SNE), but
so what? Why would that be an issue, since I just put this new dependency in,
why wouldn't it go right back to where it was?

4. I realize now I might try to add the same dependency twice unless I
guard against it. Will that be an issue? Will it error out, or just ignore
the duplication?

Again, Jack, I appreciate your help! Thanks!
 
D

Dean C

Try the code below, where MyExtPred is the path to the unique id for the task
referred to by MyKey. Using Unique ID probably isn't necessary when you are
adding successors to an external file, because the successors will be added
as phantom tasks below the external predecessor; but it is a safer practice
since the ID of other external tasks will change if you add successors. It's
only a concern if you bring in an array of possible predecessor IDs.

FilterEdit Name:="Successor List", TaskFilter:=True, Create:=True,
OverwriteExisting:=True, FieldName:="Text1", test:="equals", Value:="MyKey",
ShowInMenu:=False, ShowSummaryTasks:="NO"
FilterApply Name:="Successor List"
Selectsheet
for each mytask in active selection.tasks
If mytask.UniqueIDPredecessors = "" Then
myUIDpreds = MyExtPred
Else
myUIDpreds = mytask.UniqueIDPredecessors & "," & MyExtPred
End If
SetTaskField Field:="Uniqueidpredessors", Value:=myUIDpreds,
allselectedTasks:=True
next mytask
 
D

Dean C

I forgot to mention that although it's better to open the external file that
you are linking to, you don't need to open the files that you want to link
to; Project will do that for you the next time you open the file. Be sure to
set the Option on the View tab "Show Links Between Projects Dialog on Open,
then accept the additional successors.
 
J

Jack Dahlgren MVP

Comments inline below...

-Jack

JimS said:
Jack,
Thank you so much. After much research and your help, I've accomplished
much. I have some issues if you'll indulge me:

1. I was stepping through the task collection (for each...) on one of the
projects when somehow I ended up with a "nothing" task. I can't see how I
could be out of bounds (of course, I'm a perfect programmer -- lol.) Any
other way that could happen?

Blank lines will cause this. Most of the time I use a test like:

if not task is nothing then
.....
end if

Or you can use an onerror resume next


2. When I set interproject relationships (taskdependencies...), those
relationships show up as 'grayed-out' tasks in their respective projects.
Is
that normal? Required?

Formating of them can be controlled so that they are different.Go to format
menu, text styles, then select External Tasks.

3. I tried to delete one of the dependencies manually, but every time I
tried, I got a message saying it would foul up the schedule because of
another constraint. Now each of the task successors is constrained (SNE),
but
so what? Why would that be an issue, since I just put this new dependency
in,
why wouldn't it go right back to where it was?

Maybe it moved the tasks later. I'd be careful about a schedule where every
task is constrained to start no earlier than. In that case your dependencies
will not be very effective and you may be better off just tracking in excel.

4. I realize now I might try to add the same dependency twice unless I
guard against it. Will that be an issue? Will it error out, or just ignore
the duplication?

Test it. You can just cut and paste the code and see what happens when you
add the same dependency twice.
 

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