VBA code to select all sub tasks for a given task

P

Peter Rooney

I found a neat little trick where if I click on the row header of a task,
then click it again and drag down to the next row, Project automatically
selects all the sub tasks for that task. I can't do this in macro record mode
- all that happens is I select the next row, instaed of all sub tasks?

Could anyone advise how I can code such an operation, please - if I was
thinking Excel, it would be a "currentregion" type of thing - or am I barking
up the wrong tree?

Cheers in advance

pete
 
J

Jan De Messemaeker

Hi Peter,

First, I really wonder why one would select tasks through VBA when there are
so many methods to access the tasks you need. In fact, what I am going top
suggest is the other way around - I will define the tasks and then up to you
to use the Select method(s)

Secondly, what if any of these subtasks is a summary task? Do you want to go
another level down? And another?

So let's start by the simplest of cases. The subtasks of a task are in the
collection

Thetask.outlinechildren

You could use them for instance by

For each ChildTask in Thetask.Outlinechildren
if not childtask is nothing then

(Whatever code)

end if
next childtask

One more particle of advice
- Nearly all methods regarding subtasks and summaties have OUTLINE in them
(in case you would search)


HTH
 
P

Peter Rooney

Jan,

OK, I admit, it wasn't the best way to go about it - after reading your
hints on filtering, I did it that way instead, setting up some filters, then
calling them via the method you indicated. I don't suppose you know of a way
to automatically feed a start date into the creation of a new plan via VBA,
do you?
I'm copying a selection of data from one plan into a new one. I use the
following line of code

FileNew SummaryInfo:=True, Template:="", FileNewDialog:=False

but I still have to enter the start date.

Cheers

pete
 
P

Peter Rooney

Jan,

I used your tips on filtering from the other string and did it that way
instead - thank you!

Now, I need to copy the filtered data into a new plan. I create a new plan
with the following line of code,

FileNew SummaryInfo:=True, Template:="", FileNewDialog:=False

But still have to type in the start date for the new plan. Is there any way
in which I can use VBA to automatically feed the start date into the creation
of the new plan?

Cheers

Pete
 
J

Jan De Messemaeker

Hi Peter,

After the FileNew instruction:
Activeproject.projectstart=.... any date...

HTH
 
J

JackD

Since you want to copy over a large portion of the file, why not do a "save
as" of the current project and then delete all the unselected tasks?
 
P

Peter Rooney

Hi, Jan,

Thanks for this - I was hoping that I could somehow embed the date into the
creation of the plan, instead of doing it afterwards, so can you see any
potential problems with the following (it works, by the way)

SendKeys "19/07/04 {enter}"
FileNew SummaryInfo:=True, Template:="", FileNewDialog:=False

Cheers

Pete
 
P

Peter Rooney

Jack,

Because the wonderful plan I've inherited is more of a programme plan than a
project plan (it feeds into a timesheet system, so all activity has to be on
the same plan) and the bit that I'm copying and pasting is about 5% of the
whole.

Jan came up with a good answer using activeproject.projectstart="XX/XX/XX" ,
but I came up with the following, so that I didn't have to change the date
after the plan had been created:

SendKeys "19/07/04 {enter}"
FileNew SummaryInfo:=True, Template:="", FileNewDialog:=False

You can't see any pitfalls with this, can you? I suppose the next logical
step would be to try to trap the start date of the earliest task in the data
being copied..!

Cheers

Pete
 
J

Jan De Messemaeker

Hi Peter,

Just for the fun of it

Dim anytask as task
Dim Earliest as date

Earliest= "1/1/2049"
for each anytask in activeselection.tasks
if not anytask is nothing then
if anytask.start<earliest then earliest=anytask.start
end if
next anytask

HTH
 
J

Jan De Messemaeker

Hi,

If it works, the better!
The only problem I ever had with Sendkeys was when MS changed the layout of
a dialog box when upgrading from 98 to 2000 and my sendkeys wrote the wrong
thing.

But I fail to see any advantage of your solution as compared to mine: in
both cases the date is hard coded
And in an other post I give you a routine to calculate the earliset date of
the selected tasks
HTH
 
P

Peter Rooney

Jan,

Fun indeed! This is much too clever to be fun!
I still had to do a sendkeys "{Enter}" to dismiss the Project Information
box when I created the new plan, but was able to use your code to set the
startdate to the earliest date in my copied data.

Thanks once again.

Pete
 

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