共用方式為


Task.WBSPredecessors 屬性 (Project)

取得工作分解結構 (WBS) 代碼的任務的前置任務,以清單分隔字元分隔。 唯讀的 String

語法

expressionWBSPredecessors

表達 代表 Task 物件的變數。

範例

下列範例會向使用者查詢任務識別碼,然後將其前置任務的 WBS 碼分解成更容易使用的碼。

Sub EnumeratePredecessors() 
 Dim Task As Task 
 Dim PredTasks As Tasks 
 Dim ID As Long 
 Dim Predecessors As String 
 Dim List As String 
 Dim Count As Integer 
 
 ID = CLng(InputBox$("Enter the ID number of the task you wish to examine:")) 
 
 Set Task = ActiveProject.Tasks(ID) 
 Set PredTasks = Task.PredecessorTasks 
 Predecessors = Task.WBSPredecessors 
 Count = 1 
 
 If PredTasks.Count = 0 Then 
 List = "Task " & Task.UniqueID & ", " & Task.Name & ", has no predecessors." 
 Else 
 List = "Predecessors to task " & Task.UniqueID & ", " & Task.Name & ":" & vbCrLf & vbCrLf 
 Do While InStr(Predecessors, ListSeparator) <> 0 
 List = List & PredTasks(Count).Name & ": " & Mid$(Predecessors, 1, InStr(Predecessors, ListSeparator) - 1) & vbCrLf 
 Predecessors = Right$(Predecessors, Len(Predecessors) - InStr(Predecessors, ListSeparator)) 
 Count = Count + 1 
 Loop 
 List = List & PredTasks(Count).Name & ": " & Predecessors 
 End If 
 
 MsgBox List 
 
 Set PredTasks = Nothing 
 Set Task = Nothing 
End Sub

支援和意見反應

有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應