我有一个总项目,里面有几个子项目。
我想根据字段 Text5
的值来设置行的颜色。
当前问题:如何使用VBA代码引用第二个子项目中的行。
当我运行代码并修改子项目2中任务ID 5(在Text5
)的值时,它会修改子项目1中任务ID 5的颜色。
我该如何使用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)