Adding Subtask to a Parent via macro...

I

indyvetteguy

I have a project plan that has approximately 300 Parent Task that I
would like to explode into 3 sub task with the same name as the parent
task with a suffix added to the task. So basically I want to:
1) Copy Parent Line
2) Paste Parent Line 3 times
2) Indent Parent Lines to make them Sub Task Lines
3) Append a suffix onto each Sub Task Line to the Parent Name

When I record the macro, it naturally works for that parent, but when I
run it for the next parent, it simply replicates the previous task
names versus pulling the new parent (active line) in the project plan.

Sub Macro1()
' Macro Macro1
' Macro Recorded Sat 11/11/06 by Me.
SelectRow Row:=0
EditCopy
SelectRow Row:=1
EditPaste
EditPaste
EditPaste
SelectRow Row:=0, Height:=2
OutlineIndent
SelectTaskField Row:=0, Column:="Name"
SetTaskField Field:="Name", Value:="Develop Report A - Design"
SelectTaskField Row:=1, Column:="Name"
SetTaskField Field:="Name", Value:="Develop Report A - Code"
SelectTaskField Row:=1, Column:="Name"
SetTaskField Field:="Name", Value:="Develop Report A - Test"
SelectTaskField Row:=1, Column:="Name"
End Sub


So visually I would like the following to occur.

Current Look and Feel of Parent Task in Plan:
Develop Report A
Develop Report B
Develop Interface C


After executing the Macro on a Parent Task Line, I would like to see:
Develop Report A
Develop Report A - Design
Develop Report A - Code
Develop Report A - Test
Develop Report B
Develop Interface C

Naturally I would run the macro against each parent so as to control
what Parent Task get exploded. So basically I just want to
 
J

John

I have a project plan that has approximately 300 Parent Task that I
would like to explode into 3 sub task with the same name as the parent
task with a suffix added to the task. So basically I want to:
1) Copy Parent Line
2) Paste Parent Line 3 times
2) Indent Parent Lines to make them Sub Task Lines
3) Append a suffix onto each Sub Task Line to the Parent Name

When I record the macro, it naturally works for that parent, but when I
run it for the next parent, it simply replicates the previous task
names versus pulling the new parent (active line) in the project plan.

Sub Macro1()
' Macro Macro1
' Macro Recorded Sat 11/11/06 by Me.
SelectRow Row:=0
EditCopy
SelectRow Row:=1
EditPaste
EditPaste
EditPaste
SelectRow Row:=0, Height:=2
OutlineIndent
SelectTaskField Row:=0, Column:="Name"
SetTaskField Field:="Name", Value:="Develop Report A - Design"
SelectTaskField Row:=1, Column:="Name"
SetTaskField Field:="Name", Value:="Develop Report A - Code"
SelectTaskField Row:=1, Column:="Name"
SetTaskField Field:="Name", Value:="Develop Report A - Test"
SelectTaskField Row:=1, Column:="Name"
End Sub


So visually I would like the following to occur.

Current Look and Feel of Parent Task in Plan:
Develop Report A
Develop Report B
Develop Interface C


After executing the Macro on a Parent Task Line, I would like to see:
Develop Report A
Develop Report A - Design
Develop Report A - Code
Develop Report A - Test
Develop Report B
Develop Interface C

Naturally I would run the macro against each parent so as to control
what Parent Task get exploded. So basically I just want to

indyvetteguy,
Before I get into the "meat" of your question, let me bend your ear for
a minute. As it stands it appears you have created a first level outline
of your plan. You basically have 300 lines of general activity groups
but no actual performance tasks. Now you want to add performance tasks.
Summary lines in Project should be noun based. I other words, they
should simply summarize the intent of the underlying subtasks.
Therefore, when your first level outline is expanded it should really
have a structure like this:
Report A
Report B
Interface C
etc.
There should be no verb in the summary line task name because no effort
is being expended at that level. When the performance tasks are added,
they should be in action verb form since something is physically being
done at that level. That's why they are called performance tasks. Using
this approach your expanded plan should like like:
Report A <- noun description, no action
Design report A <- verb description, action
Code report A <- verb description, action
Test report A <- verb description, action
Report B
etc.
etc.

The above approach provides a more descriptive structure to the plan but
it will change the approach you planned to use for creating the
performance tasks in your plan.

OK, enough philosophy. A recorded macro is one way to approach this, but
expanding it to cover all 300 task lines will require a whole lot of
copying and editing of the recorded code. A much better approach would
be to set up a loop to cycle through all tasks and create the structure.
I cobbled together the following code which should work given the
starting structure you describe. Note, it will implement the description
changes I outlined above. If you do not want those, edit the code
accordingly.

Sub Create_Detail()
Dim i As Integer
Dim area As Object, par As Object, t As Object
SelectAll
Set area = ActiveSelection.Tasks
Set par = ActiveProject.Tasks
NumTsk = area.Count
i = 1
For Each t In area
t.Name = Mid(t.Name, InStr(1, t.Name, " ") + 1)
If i > NumTsk Then Exit For
par.Add Name:="Design " & t.Name, before:=t.ID + 1
par(t.ID + 1).OutlineIndent
par.Add Name:="Code " & t.Name, before:=t.ID + 2
par.Add Name:="Test " & t.Name, before:=t.ID + 3
i = i + 1
Next t
End Sub

Hope this helps.
John
Project MVP
 
I

indyvetteguy

John,

This helps but because it selects all of the columns, it explodes all
of the task in my plan into these sub task. I have alot of task that I
don't want this applied to, so I'm still trying to figure out how to
indent and apply the message to the three subtask that I've added. So
if you have a way to only execute the macro against the line being
copied, then this will work fine for me.

Regards,
J.C.
 
J

John

John,

This helps but because it selects all of the columns, it explodes all
of the task in my plan into these sub task. I have alot of task that I
don't want this applied to, so I'm still trying to figure out how to
indent and apply the message to the three subtask that I've added. So
if you have a way to only execute the macro against the line being
copied, then this will work fine for me.

Regards,
J.C.

J.C.
Well, I interpreted your original post to say you have 300 "parent"
tasks that you wanted to add 3 performance tasks each. So I guess
without more detail, I don't know what you really want.

Or here's another thought - again I'm just guessing. Use a spare flag
field to identify the selected tasks you want to expand with performance
tasks. Filter on the flag. Then run the macro I wrote on that filtered
set.

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