如何在MS项目时间表中动态添加一些任务的摘要行?
Dim ProjTasks = pj.ActiveProject.Tasks
ProjTasks.Add()
ProjTasks(1).name = "Summary Line"
ProjTasks.Add()
ProjTasks(2).name = "Task1"
ProjTasks.Add()
ProjTasks(3).name = "Task2"
ProjTasks.Add()
ProjTasks(4).name = "Task3"
您是否选择了一堆任务,然后使用" utlineindent"命令(似乎很麻烦)?
尝试下面的VBA解决方案代码,一旦选择了一些任务(假设3),它将在其上方添加摘要任务,并在其中缩进这3个任务。
Option Explicit
Sub AddSummayTask()
Dim t As Task
Dim i As Long
Dim RowsSelected() As Long
Dim FirstRow As Long
FirstRow = 10000
' redim the array of tasks selected to maximum size of 1000
ReDim RowsSelected(0 To 1000)
i = 0
' loop through all selected tasks
For Each t In ActiveSelection.Tasks
' add current task ID (row) to an array
RowsSelected(i) = t.ID
' check for the first row
If FirstRow > t.ID Then FirstRow = t.ID
i = i + 1
Next t
' redim array of tasks selected to actual size
ReDim Preserve RowsSelected(0 To i - 1)
' add a Task before the first selected row
ActiveProject.Tasks.Add Name:="Summary test", before:=FirstRow
' loop through all rows of selected tasks and indent them
For i = 0 To UBound(RowsSelected)
ActiveProject.Tasks(RowsSelected(i) + 1).OutlineIndent
Next i
End Sub