I built a form that has a "Done" button that changes the font of the selected cells to Grey and Strikethrough.
Sub SetTaskNameFontDone()
Dim T As Task
If Not (ActiveSelection.Tasks Is Nothing) Then
For Each T In ActiveSelection.Tasks
' Test for blank task row
If Not (T Is Nothing) Then
SelectTaskField Row:=T.ID, Column:="Name", RowRelative:=False
Font32Ex Color:=8355711
Font32Ex Strikethrough:=True
End If
Next T
End If
End Sub
The problem is that the Row number seems to be a physical location number, i.e. position from the top of the sheet. So if you "close" a task that has subtasks, then the Row number is no longer the same as the Task ID, and the formatting is applied to the wrong row.
Case 1: Sheet when task is open:
VBA Row # TaskID Task
1 1 ParentTask1 (open)
2 2 SubTask1-1
3 3 ParentTask2
Case 2: Sheet when task is closed (note change in row number)
VBA Row # TaskID Task
1 1 ParentTask1 (closed)
2 3 ParentTask2
Two possible approaches:
I could do OutlineShowAllTasks at the start of the routine, but that changes the way the outline appears. I haven't found an indicator for which tasks are open, so I can't memorize and restore that, as a compensation for OutlineShowAllTasks.
Save the target Task IDs, and then loop through all the rows, and compare the Task ID for each row. However, I haven't found a way to loop through all the rows and get the Task ID from the row.
How do I associate the selected task with the proper row?