question

KJames-3092 avatar image
0 Votes"
KJames-3092 asked ·

Visual Basic MS Project cell formatting question

Hello,

I have built a MS Project file that tracks the task status (i.e. in progress, done, not started, etc) and resource name associated with each task. I currently have a script that scans the entire active project and looks for the task status and colors the cell based on the status (i.e. if in progress --> color light green) and it also scans the entire active project and looks for the resource name and colors the cell a different color based on the name.

What I would like to do is write a script that looks at the value in the task status and checks the value, and if value equals done, ignore coloring that task cell AS WELL AS ignore coloring the resource name cell (sample of what I am looking for below obviously without the correct syntax since i am still a beginner at visual basic).

if not task status = done then <-- main loop
if task status = in progress then <-- sub if 1
color task status cell lightgreen
if resource name = James then <-- sub if 1 sub
color resource name cell blue
end if
end if

if task status = not started then <-- sub if 2
color task status cell orange
if resource name = James then <-- sub if 2 sub
color resource name cell blue
end if
end if
end if

Here is a copy of the code that I wrote (based on recording a macro and figuring out what I did). I have multiple of this in my code to search for different text so would be nice to be able to shrink the code length down as well.

 Dim t2 As Task
 Dim i2 As Integer
 i2 = 1
 For Each t2 In ActiveProject.Tasks
    
 SelectRow row:=i2, RowRelative:=False
    
 If Not t2 Is Nothing Then
     Find Field:="Text4", Test:="equals", Value:="Not Started"
     Font32Ex Size:="12", CellColor:=11324407 'LightOrange
 End If
 i2 = i2 + 1
 Next t2







office-vba-dev
· 1
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,
the easiest way is to use status and resource name as properties in Task Object. If Properties are changed NotifyPropertyChange inform UI. CellColor in UI is bound to Properties using ValueConverter or MultiValueConverter. In ValueConverter you check the values of bound properties and in if construct you return the desired color brush.

0 Votes 0 ·

0 Answers