vba - MS(项目)在text10中查找字符串并更改字体颜色

标签 vba fonts colors ms-project

我正在根据完成百分比和 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

关于vba - MS(项目)在text10中查找字符串并更改字体颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43100830/

相关文章:

excel - 将全名拆分为姓氏,如果姓氏有多个部分(即van,de),则为firstname

Excel VBA 更改数据透视表的数据源

excel - VBA - 获取组合框的旧值

c++ - 如何覆盖qt中的标签宽度?

ios - 核心剧情: axis alternatingBandFills with custom axis labels

arrays - 在 msoFileDialogFilePicker 之后从 SelectedItems 创建数组

Ruby Prawn - 确定单间距字体的宽度

css - 如何在我的 css 中使用阿拉伯字体?

css - Wordpress 网站不显示任何背景颜色

android - android 中的 ColorDrawable 中没有方法 "getColor"