Color coding tasks in a Microsoft Project Macro

2019-08-01 10:33发布

问题:

This seems like it should be straight forward, but I'm seeing some strange behavior. I'm attempting to color code my tasks based on a flag. It appears to be correctly coloring the tasks, but at some point in the processing the initial tasks that were colored are getting reset to black. The task that it happens on seems to be fairly inconsistent too. Here's how I'm trying to perform this task (simplified to it's barest form):

Sub ColorTasks()
    Dim t As Task
    For Each t In ActiveProject.Tasks
        SelectRow t.ID, RowRelative:=False
        Font32Ex Color:=2366701
    Next
End Sub

This code seems to work just fine for smaller data sets, but this project contains around 2,000 tasks. Any ideas?

回答1:

Yes I too am having a similar problem::

For Each t In tsks
    Select Case t.Text1
        Case "COMPLETE"
            SelectRow Row:=t.ID, RowRelative:=False
            Font32Ex CellColor:=&659B59
        Case "NOT STARTED"
            SelectRow Row:=t.ID, RowRelative:=False
            Font32Ex CellColor:=&862525
        Case "IN PROGRESS"
            SelectRow Row:=t.ID, RowRelative:=False
            Font32Ex CellColor:=&3A3AD4
    End Select
Next t

According to: http://msdn.microsoft.com/en-us/library/ff863572.aspx this should work, yet I get syntax errors every time. Only way I can get this to work is if I use the FontEx method which limits me to only 16 colors....



回答2:

I know that this is an old question but I hope it may be useful for someone with similar problem.

The mistake is that you've forgotten to add 'H' before hexadecimal number, so properly there should be:

Font32Ex CellColor:=&H3A3AD4
etc