簡體   English   中英

MS(項目)在 text10 中查找字符串並更改字體顏色

[英]MS (Project) Find Strings in text10 and change font color

我正在根據完成百分比和 text10 列中的名稱更改 MS Project 中字體的顏色。 百分比有效,但是有人可以指導我使用哪些名稱,我將不勝感激,如果例如“David”或“Darren”或兩者都在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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM