Color coding tasks in a Microsoft Project Macro

自作多情 提交于 2019-12-11 00:26:25

问题


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



回答3:


I find it easier to use RGB values.
Font32Ex CellColor:=RGB(255, 199, 206) 'Changes fill Font32Ex Color:=RGB(156, 0, 6) ' Changes font color

Using your code, I turned my entire sheet to red on pink, 350 tasks. I don't have a means to test it on 2000 though without a lot of extra work.



来源:https://stackoverflow.com/questions/5951578/color-coding-tasks-in-a-microsoft-project-macro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!