MS(项目)在文本中查找字符串10并更改字体颜色



>我正在根据完成百分比和文本10列中的名称更改MS Project中的字体颜色。 百分比有效,但是有人可以指导我的名字,我会感激不尽,我想用蓝绿色突出显示例如"大卫"或"达伦"或两者都在Text10字段中。

任何帮助都感激不尽。

Sub text()
Dim Ctr As Integer
ViewApply "Gantt Chart"
OutlineShowAllTasks
FilterApply "All Tasks"
SelectAll
For Ctr = 1 To ActiveSelection.Tasks.Count
    SelectRow Row:=Ctr, rowrelative:=False
    If Not ActiveSelection.Tasks(1) Is Nothing Then
        If ActiveSelection.Tasks(1).Text10 = ("David") & ("Darren") Then
            Font Color:=pjTeal
        Else
            If ActiveSelection.Tasks(1).PercentComplete = 100 Then
                Font Color:=pjGreen
            Else
                If ActiveSelection.Tasks(1).PercentComplete = 0 Then
                    Font Color:=pjBlack
                Else
                    If ActiveSelection.Tasks(1).PercentComplete > 0 < 100 Then
                        Font Color:=pjBlue
                    Else
                    End If
                End If
            End If
        End If
    End If
Next Ctr
End Sub

更改:

If ActiveSelection.Tasks(1).Text10 = ("David") & ("Darren") Then

自:

If ActiveSelection.Tasks(1).Text10 = "David" Or ActiveSelection.Tasks(1).Text10 = "Darren" Then

编辑1:更好的编码风格(未经测试,因为我没有在家里安装MS-Project - 明天早上可以测试(

Option Explicit
Sub text()
ViewApply "Gantt Chart"
OutlineShowAllTasks
FilterApply "All Tasks"
Dim T As Task
For Each T In ActiveProject.Tasks
    If Not T Is Nothing Then
        SelectRow T.UniqueID, RowRelative:=False '<-- there's no escape, in Ms-Project you need to select the Task's row in order to modify it's Font color
        If T.Text10 = "David" Or T.Text10 = "Darren" Then
            Font Color:=pjTeal
        Else
            Select Case T.PercentComplete
                Case 100
                    Font Color:=pjGreen
                Case 0
                    Font Color:=pjBlack
                Case Else
                    Font Color:=pjBlue
            End Select
        End If
    End If
Next T
End Sub

编辑 2:添加了用于按 PO 添加信息的新逻辑。

Option Explicit
Sub ColorTasks()
ViewApply "Gantt Chart"
OutlineShowAllTasks
FilterApply "All Tasks"
Dim T As Task
For Each T In ActiveProject.Tasks
    If Not T Is Nothing Then
        SelectRow T.ID, RowRelative:=False
        Select Case T.Text10
            Case "David"
                 Font Color:=pjBlue
            Case "Mary"
                Font Color:=pjTeal
            Case "Bill"
                Font Color:=pjBlack
            Case "Sandra"
                Font Color:=pjPurple
        End Select
        ' I think you wanted this outside the case of the people in Text10
        If T.PercentComplete = 100 Then
            Font Color:=pjGreen
        Else
            If DateDiff("d", T.Finish, ActiveProject.CurrentDate) > 0 Then
                Font Color:=pjRed
            End If
        End If
    End If
Next T
End Sub
Sub test()
Dim Ctr As Integer
ViewApply "Gantt Chart"
OutlineShowAllTasks
FilterApply "All Tasks"
SelectAll
For Ctr = 1 To ActiveSelection.Tasks.Count
    SelectRow Row:=Ctr, rowrelative:=False
    If Not ActiveSelection.Tasks(1) Is Nothing Then
        If ActiveSelection.Tasks(1).Text10 = "David" Then
            Font Color:=pjBlue
        Else
        If ActiveSelection.Tasks(1).Text10 = "Mary" Then
            Font Color:=pjTeal
        Else
        If ActiveSelection.Tasks(1).Text10 = "Bill" Then
            Font Color:=pjBlack
        Else
        If ActiveSelection.Tasks(1).Text10 = "Sandra" Then
            Font Color:=pjPurple
        Else
        If ActiveSelection.Tasks(1).PercentComplete = 100 Then
            Font Color:=pjGreen
        Else    
        If ActiveSelection.Tasks(1).finish < currentdate Then 
            Font Color:=pjRed
        End If
        End If
        End If
        End If
        End If
        End If
        End If
    Next Ctr
End Sub

最新更新