MS Project& VBA:基于PercentComplete更新行

时间:2016-04-25 19:13:17

标签: vba ms-project

我试图在MS Project中创建一个VBA进程,该进程将根据"%Complete"列值。当我输入值而不是打开,关闭或运行项目时,我试图让它更新。以下是两个代码集。

1。是我对描述的尝试。

我的着色(不幸的是)只是由第一个ELSE期间c_pcStatus的值决定

Dim t As Task
Dim prj As Project
Dim c_pcStatus
Dim app As Application
Set app = MSProject.Application
Set prj = ActiveProject

    For Each t In prj.Tasks
        If t.PercentComplete = 100 Then
            c_pcStatus = 100
        ElseIf t.PercentComplete >= 5 And t.PercentComplete < 100 Then
            c_pcStatus = 50
        Else
            c_pcStatus = 0 'SO note:This value entry is the only one recognized
        End If

    Next t
    With app
        .ScreenUpdating = False 'allow screen refreshing

        .FilterApply "&All Tasks"
        .OutlineHideSubTasks
        .OutlineShowAllTasks
        .SelectTaskColumn Column:="PercentComplete"

        If c_pcStatus = 100 Then
            Font Color:=pjGreen, Bold:=True
            Font32Ex CellColor:=&H90EE90
        ElseIf c_pcStatus = 50 Then
            Font Color:=pjBlue, Bold:=True
        Else
            Font Color:=pjBlack, Bold:=False
            Font32Ex CellColor:=&HFFFFFF
        End If
    End With

2是一个可以工作的VBA,但是在逐个任务的基础上运行,通常需要永久。

Dim tskT As Task
For Each tskT In ActiveProject.Tasks
    Select Case tskT.PercentComplete
        Case 0 To 0
            SelectRow Row:=tskT.ID, RowRelative:=False
            Font Color:=pjBlack, Bold:=False
            Font32Ex CellColor:=&HFFFFFF
        Case 5 To 99
            SelectRow Row:=tskT.ID, RowRelative:=False
            Font Color:=pjBlue, Bold:=True
            'Font32Ex CellColor:=&HFFFF99
            Font32Ex CellColor:=&HFFFFFF 'clear
        Case 100 To 100
            SelectRow Row:=tskT.ID, RowRelative:=False
            Font Color:=pjGreen, Bold:=True
            Font32Ex CellColor:=&H90EE90
    End Select
Next tskT

非常感谢您提供的任何帮助

0 个答案:

没有答案