Reference new inserted Task

S

SpaceCamel

How do you reference a new task created with the insertRow method?

With ActiveProject.Tasks(tID)
I get undefined.
 
M

Maurice Birchler

Try using the .Add method to create a new task to the Tasks collection. You
wil then be able to reference the new item easily enough.
 
J

John

SpaceCamel said:
How do you reference a new task created with the insertRow method?

With ActiveProject.Tasks(tID)
I get undefined.

SpaceCamel,
Maybe it fails because there is no "InsertRow" Method in Project! There
is however a "RowInsert" Method :)

If a blank row is inserted (that's all you will get by using the
RowInsert Method), there is no Task object to reference. A better
approach would be to use the Add Method on a Task collection. For
example, the following line of code will add a new task named "Do
something" right before the existing Task ID 5. The new task will then
become Task ID 5 as all tasks below it are shifted down and renumbered.
ActiveProject.Tasks.Add "Do something", 5

Hope this helps.
John
Project MVP
 
S

SpaceCamel

Thanks for your replys. I did find the Tasks.add method and it worked. But
since I needed to repeat the fields from the previous task I ended up using
the "EditCopy" & "EditPaste" methods. This worked but I have to show/expand
all Tasks to the the row numbers to work right.

Do you happen to know a way to copy a task without having to use
"EditCopy/Paste". I don't like have to expand all the tasks.

What the macro does is split a task into two tasks, maintaining fields and
links.
 
J

John

SpaceCamel said:
Thanks for your replys. I did find the Tasks.add method and it worked. But
since I needed to repeat the fields from the previous task I ended up using
the "EditCopy" & "EditPaste" methods. This worked but I have to show/expand
all Tasks to the the row numbers to work right.

Do you happen to know a way to copy a task without having to use
"EditCopy/Paste". I don't like have to expand all the tasks.

What the macro does is split a task into two tasks, maintaining fields and
links.


SpaceCamel,
The only other way I know to replicate a task is to read the relevant
properties of it (e.g. Name, Duration, links, resources, etc.) and then
use the Add Method to create a new task and format it using the read
data. By using this approach all the work can be done in the background
(i.e. no task selection as required by Copy/Paste).

You mention that you are splitting tasks. It's not clear if you mean
"Split" as defined by Project or simply breaking a single task into two
tasks. If it's the former you might want to look at the Split Method.

Hope this helps.
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