【发布时间】:2020-12-02 22:06:12
【问题描述】:
我有一个主项目,里面有几个子项目。
我想根据字段Text5 的值来格式化行的颜色。
当前问题:如何使用 VBA 代码引用第二个子项目中的行。
当我运行代码并修改任务 ID 5(在子项目 2 中)中的 Text5 值时,它会修改任务 ID 5 的颜色,但会修改子项目 1 的颜色。
如何使用SelectRow 并添加对所需子项目的引用?
我的代码(相关部分)
Sub FormatChangedTasks()
Dim SubPrj As Subproject
Dim Tsk As Task
Dim i As Long
For Each SubPrj In ActiveProject.Subprojects
' compare the name of Sub-Project with the one saved in the "Stack" srray
If SubPrj.SourceProject.Name = ModifiedPrjName Then
For Each Tsk In SubPrj.SourceProject.Tasks
If Not Tsk Is Nothing Then
i = Tsk.ID
' check if Tsk.Text5 value has changed from value in "StatusStackArr" array
If StatusStackArr(i - 1).StatusOldVal <> Tsk.Text5 Then
' **** at the line below it selects the Row from the top
' (not the desired Sub-Project) ******
SelectRow Row:=i, RowRelative:=False
' --format entire row --
Select Case Tsk.Text5 ' Get the Field's used field, not name
Case "R", "Y", "G"
FontEx CellColor:=7, Color:=0
FontEx Italic:=False ' Font regular
Case "Complete"
FontEx Italic:=True ' Font Italic
FontEx CellColor:=15, Color:=14 ' Background Silver ; font Gray
End Select
' rest of code (un-relevant)
【问题讨论】:
标签: vba ms-project