How to select a particular task row

M

meg99

using 2007. I have a macro that finds a task coded "C" and then adds
a task under it. The code is below. The problem is that after the
first pass it does not select the proper row. Anybody know what I
need to do?


Sub AddTask()
Dim TskRow as Integer, TskRowC As Integer
Dim EACTvalue As String
Dim Tsk As Task

SelectTaskColumn Column:="Name"

For Each Tsk In ActiveSelection.Tasks
TskRow = Tsk.ID
EACTvalue = Tsk.Text4
If EACTvalue = "" Then
Exit Sub
End If

If EACTvalue = "C" Then
TskRowC = TskRow

'==first time thru the next command works fine - selects
the proper row
'==and inserts a new task etc
'==2nd time thru it selects and then inserts 14 rows down

SelectTaskField Row:=TskRowC, Column:="Name"
EditInsert
SelectTaskField Row:=-1, Column:="Name", Width:=5,
Height:=1
FillDown
SetTaskField Field:="Text4", Value:="T"
End If

Next
End Sub

meg99
 
M

meg99

Hi,

First make sure that IDs map row numbers!
- Eliminate External tasks if any
Start with
filterapply "all tasks"
Outlineshowalltasks

HTH
--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620













- Show quoted text -

Jan,
I have done that. The first "C" task is row 12 (also ID 12). The
macro selects the row, enters a new row below it, fills down etc.
Everything works fine. The next "C" task is row 14 (also ID 14).
When I check TskRowC, it shows 14. However, the next command -
SelectTaskField Row:=TskRowC, Column:="Name" - selects 14 rows down
from that and then the next comman - EditInsert - inserts the new task
there. I am completely puzzled.

meg99
 
J

Jan De Messemaeker

Gotcha!
That Selecttaskfield needs Rowrelative:=false, if not it ADDS teh 14 to the
current selection' row!

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
Hi,

First make sure that IDs map row numbers!
- Eliminate External tasks if any
Start with
filterapply "all tasks"
Outlineshowalltasks

HTH
--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:http://users.online.be/prom-ade/Calendar.pdf"meg99"













- Show quoted text -

Jan,
I have done that. The first "C" task is row 12 (also ID 12). The
macro selects the row, enters a new row below it, fills down etc.
Everything works fine. The next "C" task is row 14 (also ID 14).
When I check TskRowC, it shows 14. However, the next command -
SelectTaskField Row:=TskRowC, Column:="Name" - selects 14 rows down
from that and then the next comman - EditInsert - inserts the new task
there. I am completely puzzled.

meg99
 
J

Jack Dahlgren

Try this:

Sub repeatafterc()
For Each Task In ActiveProject.Tasks
If Task.Text4 = "c" Then
ActiveProject.Tasks.Add Name:="NewTask", before:=Task.ID + 1
End If
Next Task
End Sub
 
M

meg99

Try this:

Sub repeatafterc()
For Each Task In ActiveProject.Tasks
If Task.Text4 = "c" Then
ActiveProject.Tasks.Add Name:="NewTask", before:=Task.ID + 1
End If
Next Task
End Sub

Jack,
That worked great! - much simpler than what I was trying to do. Is
there a way to populate other fields other than Name when the new task
is created?

meg99
 
J

Jan De Messemaeker

Hi,

Yes, as follows:

Set NuTask=ActiveProject.Tasks.Add (Name:="NewTask", before:=Task.ID + 1)
Nutask.text7="Whatever"
Nutask.constrainttype=pjalap
HTH
......
--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
Try this:

Sub repeatafterc()
For Each Task In ActiveProject.Tasks
If Task.Text4 = "c" Then
ActiveProject.Tasks.Add Name:="NewTask", before:=Task.ID + 1
End If
Next Task
End Sub

Jack,
That worked great! - much simpler than what I was trying to do. Is
there a way to populate other fields other than Name when the new task
is created?

meg99
 

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