Update correct task row within a group of selected tasks

D

dbonline

I would like to update the font color of a selected group of tasks in my
project. The problem I have is that if any rows in or before this selected
group are colapsed, the wrong rows are updated.
Below is the code I wrote. It works fine if all tasks are expanded.

Sub Change_Font_to_Red()
Dim SelTask As Task

For Each SelTask In ActiveSelection.Tasks

SelectRow Row:=SelTask.ID, RowRelative:=False
Font Color:=1
SelectTaskField Row:=0, Column:="Text3"
SetTaskField Field:="Text3", Value:="U"
Next SelTask
End Sub
 
J

John

dbonline said:
I would like to update the font color of a selected group of tasks in my
project. The problem I have is that if any rows in or before this selected
group are colapsed, the wrong rows are updated.
Below is the code I wrote. It works fine if all tasks are expanded.

Sub Change_Font_to_Red()
Dim SelTask As Task

For Each SelTask In ActiveSelection.Tasks

SelectRow Row:=SelTask.ID, RowRelative:=False
Font Color:=1
SelectTaskField Row:=0, Column:="Text3"
SetTaskField Field:="Text3", Value:="U"
Next SelTask
End Sub

dbonline,
As you found out, the row indexing when using a selection object is
based on the visible rows on the screen, not on the ID of the task row.

If you are trying to color all visible fields of the selected task rows,
the following code lines will do it:

SelectAll
Font Color:=pjRed

If in addition you want to set Text3 to "U" for those same selected task
rows, use the following:

SelectTaskColumn Column:="Text3"
SetTaskField Field:="text3", Value:="U", allselectedtasks:=True

Hope this helps.
John
Project MVP
 
D

dbonline

Jan,

Thanks for the reply. Is there someway to save the filtering the user
applied? If I used your suggestion, I would want to reapply any filtering
the user did after changing the color and updating the text field. The
filter may not be predefined, it may have been applied column by column by
the user.

Thanks,

Dean
 
D

dbonline

John,

Thanks for your reply. I tried your suggestion and found that no matter
what rows I selected, the macro selected all visible rows and changed them.
I just wanted to change the rows selected by the user. Maybe I just
implemented your suggestion incorectly. Here is what I did:

Sub Change_Font_to_Red()
Dim SelTask As Task

For Each SelTask In ActiveSelection.Tasks

SelectAll
Font Color:=pjRed
SelectTaskColumn Column:="Text3"
SetTaskField Field:="Text3", Value:="I", allselectedtasks:=True
Next SelTask
End Sub

Thanks.
 
J

Jan De Messemaeker

Hi,

Well Sort of. You cannottrace or reconstrue the filtering conditions the
user applied, but you can reset the exact result of his filtering as follows

Before changing to all tasks
for each anytask in activeproject.tasks
if not anytask is nothing then
anytask.flag19=false
end if
next anytask
selectall
for each SelTask in activeselection.tasks
if not seltask is nothing then
seltask.flag19=true
end if
next seltask

Then when you want to reset
Flag19Filter.apply

That implies you first make a filter with the sole condition Flag19 equels
Yes, and Show Summary tasks OFF.

Hoipe this helps,

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

dbonline

Jan,

Thanks again for the reply. So it looks as if I can get all the correct
rows back, but not the filter conditions. That may work. I'll give it a try.

Thanks.
 
J

John

dbonline said:
John,

Thanks for your reply. I tried your suggestion and found that no matter
what rows I selected, the macro selected all visible rows and changed them.
I just wanted to change the rows selected by the user. Maybe I just
implemented your suggestion incorectly. Here is what I did:

Sub Change_Font_to_Red()
Dim SelTask As Task

For Each SelTask In ActiveSelection.Tasks

SelectAll
Font Color:=pjRed
SelectTaskColumn Column:="Text3"
SetTaskField Field:="Text3", Value:="I", allselectedtasks:=True
Next SelTask
End Sub

Thanks.

abonline,
I assumed the selected rows were the only rows visible, such as would be
true if a filter were applied to select the desired tasks. If the user
is selecting just a limited number of task rows in the visible view,
then the code I suggested will not do what you want. To do the latter it
is even simpler. Just use the following code, it will set the font color
on the actively selected task rows - all at once, and then set the Text3
field to "U"

Sub Change_Font_to_Red()
Dim st as Task
Font Color:=pjRed
For Each st in Activeselection.Tasks
st.Text3 = "U"
Next st
End Sub

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