Applying a macro to linked projects

G

ggarmon

I have the following peice of code that changes text color based on
the task status (thanks Jan). The code works fine except when I
expand a linked project. The tasks in the linked project do not
appear in the correct colors. Is there a way to remedy that? The
code runs when the project is opened.

Private Sub Project_Open(ByVal pj As Project)
ViewApply "Gantt Chart"

FilterApply "All Tasks"

OutlineShowAllTasks


For Each Tsk In ActiveProject.Tasks
If Not Tsk Is Nothing Then

Select Case Tsk.Status
Case pjLate

SelectRow Row:=Tsk.ID, RowRelative:=False
Font Color:=pjRed

Case pjComplete
SelectRow Row:=Tsk.ID, RowRelative:=False
Font Color:=pjGreen

Case pjOnSchedule
SelectRow Row:=Tsk.ID, RowRelative:=False
Font Color:=pjBlue

Case Else
SelectRow Row:=Tsk.ID, RowRelative:=False

Font Color:=pjBlack
End Select
End If 'Nothing
Next Tsk
SendKeys ("^{HOME},^s")
End Sub
 
J

John

I have the following peice of code that changes text color based on
the task status (thanks Jan). The code works fine except when I
expand a linked project. The tasks in the linked project do not
appear in the correct colors. Is there a way to remedy that? The
code runs when the project is opened.

Private Sub Project_Open(ByVal pj As Project)
ViewApply "Gantt Chart"

FilterApply "All Tasks"

OutlineShowAllTasks


For Each Tsk In ActiveProject.Tasks
If Not Tsk Is Nothing Then

Select Case Tsk.Status
Case pjLate

SelectRow Row:=Tsk.ID, RowRelative:=False
Font Color:=pjRed

Case pjComplete
SelectRow Row:=Tsk.ID, RowRelative:=False
Font Color:=pjGreen

Case pjOnSchedule
SelectRow Row:=Tsk.ID, RowRelative:=False
Font Color:=pjBlue

Case Else
SelectRow Row:=Tsk.ID, RowRelative:=False

Font Color:=pjBlack
End Select
End If 'Nothing
Next Tsk
SendKeys ("^{HOME},^s")
End Sub

ggarmon,
Well, yes there is a way to do it but remember that inserted projects
are not actually part of the master. If you change font color of
subproject task data at the master level it will NOT change that color
in the actual subproject, the color change will only show at the master
level. There is a way to change the color of the actual subproject task
data but the code would have to open and select the subproject task
itself.

That said, to change the color at the master level, expand the
subproject (OutlineShowTasks expandinsertedprojects:=True), and then set
up an object of all tasks in the current view and loop on those. For
example,
SelectTaskColumn
Set area = ActiveSelection.Tasks

Hope this helps.
John
Project MVP
 
J

Jan De Messemaeker

Hi,

You should have said that from the start: the tasks in the view do not
belong to the master project so you do not access them. Instead, use this
method to go to the tasks:

Selectall
Tall=activeselection.tasks.count
for counter=1 to tall
selectrow row:=counter, rowrelative:=false
set tsk=activeselection.tasks(1)
if not tsk is nothing then
.....

end if 'nothing
next counter

HTH


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

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