Task.LinkPredecessors メソッド (Project)

タスクに 1 つ以上の先行タスクを追加します。

構文

LinkPredecessors( _Tasks_, _Link_, _Lag_ )

Task オブジェクトを表す変数。

パラメーター

名前 必須 / オプション データ型 説明
タスク 必須 オブジェクト型 (Object) 指定された タスク または タスク オブジェクトでは、 で指定されたタスクの先行タスクになります。
Link 省略可能 長整数型 (Long) リンクを設定するタスク間の関係を示す定数を指定します。 使用できる定数は、PjTaskLinkType クラスの定数のいずれかです。 既定値は、 pjFinishToStart です。
Lag 省略可能 バリアント型 (Variant) リンクされたタスク間のラグ タイムの期間を指定する文字列です。 タスク間にリード タイムを指定するには、 Lag に負の値として評価される式を使用します。

次の使用例は、タスク名の入力を求めるメッセージを表示し、ユーザーが指定したタスクを現在選択されているタスクの先行タスクとして設定します。

Sub LinkTasksFromPredecessor() 
    Dim Entry As String   ' Task name entered by user 
    Dim T As Task         ' Task object used in For Each loop 
    Dim I As Long         ' Used in For loop 
    Dim Exists As Boolean ' Whether or not the task exists 
 
    Entry = InputBox$("Enter the name of a task:") 
 
    Exists = False ' Assume task doesn't exist. 
 
    ' Search active project for the specified task. 
    For Each T In ActiveProject.Tasks 
        If T.Name = Entry Then 
            Exists = True 
            ' Make the task a predecessor of the selected tasks. 
            For I = 1 To ActiveSelection.Tasks.Count 
                ActiveSelection.Tasks(I).LinkPredecessors Tasks:=T 
            Next I 
        End If 
    Next T 
 
    ' If task doesn't exist, display an error and quit the procedure. 
    If Not Exists Then 
        MsgBox ("Task not found.") 
        Exit Sub 
    End If 
End Sub

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。