Adding Subtask through a plan

J

Jon Birt

Hi
I am a novice at this so any help would be appreciated.

I have several large project plans to do this for. I am trying to automate
an update where I have Filtered to a population of tasks, and I wish to loop
through those tasks (making sure it is not a summary task) and insert after
each one a number of sub-tasks with information derived from the, to be,
summary task. I have tried using my limited VBA skill set but very little
seems to go in the right place or with the correct level on indentation.

Thank-you all in advance.
 
J

John

Jon,
I see your post has been hanging for a few days without a reply. You
mentioned you tried some VBA but had problems. Could you post your code?
Maybe we could ferret out some problems and get you headed in the right
direction.

John
 
J

Jon

John

Thank-you - my code is included below.
The main issue is that I add tasks OK, but that I continue to add task to
the end of the selection, all as subordinate to the last inserted pair.
My assumption is that I should rework based, not around a Filter and For
Each....Next loop, but have the code identify each task required for the
update as it goes through the entire project.
I have used this For Each ....Next loop process before to update tasks, but
not to insert new tasks.

Sub InsTsks()

Dim ProjTasks As Tasks
Dim ProjTask As Task
Dim valWork As Long
Dim WorkCalc As String
Dim Newtask As Task
Dim OldTask As Task

Set ProjTasks = ActiveSelection.Tasks

For Each ProjTask In ProjTasks 'these if statements
step through all tasks in the project
If Not (ProjTask Is Nothing) Then 'this handles blank line
in the file
If ProjTask.Summary = False Then 'this handles summary
tasks which are only allowed to be fixed duration
valWork = ProjTask.Work ' Stuff for updating
effort
WorkCalc = valWork * 20 / 100

Set OldTask = ProjTask
Set Newtask = ActiveProject.Tasks.Add(Name:="Sub Taks 1",
Before:=OldTask.ID + 1)
Newtask.OutlineIndent
' Do all the task updates here
' SetTaskField Field:="Work", Value:=WorkCalc

Set Newtask = ActiveProject.Tasks.Add(Name:="Sub Taks 2",
Before:=OldTask.ID + 2)
' Do task Updates here
' SetTaskField Field:="Work", Value:=WorkCalc

SelectTaskField Row:=Newtask + 1, Column:="Name" ' Debug
Line
MsgBox "Current Task " & ProjTask.Name, vbOKOnly, "Task" '
Debug Line

End If
End If
Next ProjTask


End Sub
 
J

Jan De Messemaeker

Hi Jon

Think of something like

Do While Nutask.outlinelevel>2
nutask.outlineoutdent
loop

In othe rwords, the instructions you need to adjust outline levels are
outlineindent and outlineoutdent.
HTH

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
Project Management Consultancy
Prom+ade BVBA
32-495-300 620
 
J

Jon

Thank-you for your time Jan - however, the issue not with the promotion or
demotion of tasks.
I have some large plans, with several hundred tasks at the lowest level. I
would like to automate the process of making each of the tasks -(say "Progam
xyz component") to have a series of sub tasks (e.g. Confirm Spec, update
models, QA review, code, unit test, etc.)
The process for the code below works correct (you have to step through the
macro), but will continue to add the group of sub-tasks to the end of the
selection as inifinium, and does not end the For Each...Next loop.

Jon
 
J

Jan De Messemaeker

Sorry, read too fast.

Added tasks join the collection thus are themselves handled in a For Each
loop

I would try this
TheMax=activeproject.tasks(activeproject.tasks.count).uniqueid
and before the "Next" statement looping back to the for each
if oldtask.uniqueid=themax then exit for

Haven't studied it in depth but this should always halt your for next loop

HTH







--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
Project Management Consultancy
Prom+ade BVBA
32-495-300 620
 

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

Similar Threads


Top