MS Project 中是否有 VBA 代码可以根据完成百分比值更改任务行的背景颜色?

问题描述 投票:0回答:1

当代码运行时,它会逐行遍历整个文档,但会将每一行更改为红色阴影。有谁知道如何根据完成百分比改变颜色?附加帮助:有谁知道如何让代码在带有任务信息的最后一行之后停止运行?

我创建了一个 VBA,我想根据 Microsoft Project 中的完成百分比值更改整个任务行的背景颜色。我创建了以下代码:

Sub Test2()

Dim t As Task
Dim i As Integer

i = 1
For Each t In ActiveProject.Tasks


       SelectRow Row:=i, rowrelative:=False

       Select Case t.PercentComplete
           Case 100
           Font32Ex CellColor:=vbGreen
           Case 2 - 99
           Font32Ex CellColor:=vbYellow
           Case Else
           Font32Ex CellColor:=vbRed

       End Select

i = i + 1
Next t
End Sub
vba conditional-formatting ms-project
1个回答
0
投票

试试这个:

Sub colorrows()
FilterEdit Name:="test", TaskFilter:=True, Create:=True, OverwriteExisting:=True, _
    FieldName:="% Complete", Test:="equals", Value:=100
FilterApply Name:="test"
SelectAll
FontEx color:=pjGreen
FilterEdit Name:="test", TaskFilter:=True, Create:=True, OverwriteExisting:=True, _
    FieldName:="% Complete", Test:="is greater than or equal to", Value:="2", ShowInMenu:=True
FilterEdit Name:="test", TaskFilter:=True, NewFieldName:="% Complete", Test:="is less than or equal to", _
    Value:="99", Operation:="And"
FilterApply Name:="test"
SelectAll
FontEx color:=pjYellow
FilterEdit Name:="test", TaskFilter:=True, Create:=True, OverwriteExisting:=True, _
    FieldName:="% Complete", Test:="equals", Value:=0
FilterApply Name:="test"
SelectAll
FontEx color:=pjRed
FilterClear

End Sub
© www.soinside.com 2019 - 2024. All rights reserved.