Project 2003: Changing text color in task in VBA, based on cell da

N

NordicWally12

This seems like it should be a very simple first project, but I can't get it
right.

I want to create a macro that will run through all tasks in a project,
changing all a task's_text_ color on a row (not Gantt chart) to pjGreen if
the that task has % Completion == 100. During my Monday team meetings, I can
focus on what the team is saying, then color-code the lines afterwards with a
global post-processing macro.

The code I have currently _will_ run through the tasks and - based on the
Debug.Print - is indeed finding the 100% lines. But it isn't changing the
text color.

Here's what I've got so far:

Sub DCT_greenDone()
' Macro NW12_greenDone
' Macro Recorded Fri 3/9/07.

'This macro sets a task record's text to green if 100% Complete

Dim trow As Task

For Each trow In ActiveProject.Tasks
If Not trow Is Nothing Then
If trow.PercentComplete > 99 Then
Debug.Print trow.ID, trow.Name, trow.PercentComplete
SelectRow Row:=trow.ID, RowRelative:=False
TextStyles Item:=4, Color:=pjGreen ' Doesn't seem to change
anything
' Font Color:=pjGreen ' Nope, changes all records
Else
End If
End If
Next trow
End Sub

Both "Font" and "TextStyles" work if I do a macro record on a single line.
Any suggestions, or am I trying to carry water in a sieve here ? ;)
 
N

NordicWally12

Thanks for the reply.

Further testing demonstrated that the "Font Color" was not doing _all_ the
lines.... but it isn't working properly. Some lines that are 100% are not
getting colored and many that are not 100% _are_ turned green.

I created a new, test file and put in a few lines and the macro works dandy
on it.
I then copied over all the tasks (about 1250 of them) into the new project
and it failed again. Don't notice any consistancies between those that don't
fail.

The only columns I've added are "% Complete", "Priority" and Text1 (renamed
to "Dept").

Good to know my logic was right, anyway :)
 
J

Jan De Messemaeker

Hi,

Attention to filters and closes summary tasks! ID and row are not
necessarily the same value
Before the macro core do not forget to code
Outlineshowalltasks
filterapply "All Tasks"
HTH
 
N

NordicWally12

ID and row are not necessarily the same value

Ah, so. I did not realize that. :)
I had filtering at "All Tasks" already, but there were previous milestones
roled up.

Adding those two to the top of the macro seems to have resolved the issue.

Thanks to both you and Rod, Jan :)
 
J

Jimmy

Using your code below, what happens for me is all column headings and all row
numbers (the ID number in the gray box) change to green .... nothing else.
Did I copy something incorrectly?

Sub DCT_greenDone()

'This macro sets a task record's text to green if 100% Complete

Outlineshowalltasks
filterapply "All Tasks"

Dim trow As Task

For Each trow In ActiveProject.Tasks
If Not trow Is Nothing Then
If trow.PercentComplete > 99 Then
Debug.Print trow.ID, trow.Name, trow.PercentComplete
SelectRow Row:=trow.ID, RowRelative:=False
TextStyles Item:=4, Color:=pjGreen
'What does the 4 buy me? Help has items like pjAll, pjSummary, etc.
Else
End If
End If
Next trow
End Sub
 
J

Jan De Messemaeker

Hi,

This needs a word of explanation.
There are two ways to format text in Project.
Text Styles reformat certain types of text for certain types of tasks
INDEPENDENT OF WHAT IS SELECTED
Font reformats THE SELECTION.

When you use textstyles, no need to select anything.
The selection is done by the item:= parameter.
For instance 4 stands for Row and Column Titles.
But by all means, that is not what you want to do, why else go through all
the pain of selecting the rows.?

So instead of textstyles you need
Font Color:=pjgreen

Hope this helps,
 
P

Prasad Basani

Hi,

I am inserting a new task and then I want to change the font. I tried the
following code. When I ran the macro, it is applying the font for the 25th
row after the currently inserted task.

Dim newTask As Task
Set newTask = ActiveProject.Tasks.Add(CStr(rs!Client) & " - " &
CStr(rs!Location) & " - " & CStr(rs!Project))
SelectRow Row:=newTask.ID, RowRelative:=False
Font Name:="Arial", Size:=8, Bold:=True

I am also inserting 8 subtasks after this this newTask.

I tried TextStyles instead of Font. But I didn't get the result.
TextStyles Item:=4, Size:=8, Bold:=True, Color:=pjGreen

Can somebody tell me if I am missing anything?

Thanks
Basani
 

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