tasks and levels

G

greg

Hello, I am a newbie to MS Project. And I have a basic question.

I have 3 levels. Where each one is indented.

Task1

Task2

Task3

I am trying to figure out how to know this programmatically. I can see the
following:

ThisProject.Tasks.Count = 3



ThisProject.Tasks(1).type = 1

ThisProject.Tasks(2).type = 1

ThisProject.Tasks(3).type = 0



ThisProject.Tasks(1).name = task1

ThisProject.Tasks(2).name = task2

ThisProject.Tasks(3).name = task3



So it looks like type = 1 is a group. And type = 0 is an actual task.

But I am trying to figure out how to know that task1 is the first level,
task2 is the second and task3 is the task. And how to programmatically
gather the level information.



Any help would be appreciated

Thanks,
 
J

JackD

The usual test for a summary task is

sub AmIaSummary()
if activeselection.tasks(1).summary then
msgbox "I am a summary task"
end if
end sub

if task.summary is true then task is a summary task.

As for outline level,

ThisProject.tasks(1).OutlineLevel

will return the outline level.

Here is a simple example of how to traverse the chain of child tasks and
write out their outline level
This macro presumes that at least one task is selected - otherwise it will
get an error - it uses the first task in the selection. Others are ignored.

Sub FunWithOutlineLevel()
Dim t As Task
Dim mystr As String
'set the value of mystr to a blank
mystr = ""
'use the first task in the active selection
Set t = ActiveSelection.Tasks(1)
'call the recursive function which adds the information about the current
task to the string
children t, mystr
'display the string
MsgBox mystr
End Sub

Function children(ByVal t As Task, ByRef mystr As String)
mystr = mystr & t.Name & " Outline Level: " & t.OutlineLevel & " Parent
task: " & t.OutlineParent.Name & vbCrLf
'recurses through each child of the parent task and its children and so on.
For Each t In t.OutlineChildren
children t, mystr
Next t
End Function

Together this should be enough information for you to figure out just about
anything about a particular task and whether it fits your criteria.

-Jack
 
J

JackD

As a further explanation of what task.type is:

"Returns or sets how the units, duration, and work on a task are calculated.
Can be one of the following PjTaskFixedType constants: pjFixedUnits,
pjFixedDuration, or pjFixedWork."

Each of these constants also has a numeric value. For example pjFixedUnits =
0.

-Jack
 

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