如何在 MS 项目中排除 vba 代码的某些行

How to except some rows for vba code in MS project

我已经在任务中为更新前任编写了代码并且它有效。 例如新任务由线切割、edm和cmm过程组成,它可以自动更新前任。但只是为了某些任务,我不想更新前任。 我想添加这个 except for unique id =2,3 我应该在我的代码中添加什么。 这是我的代码

Sub AutoPredecessorRepairLevel3()

    Dim TA As Task
    Dim TB As Task

    For Each TA In ActiveProject.Tasks
        If (TA.Name Like "*report*") Then
        For Each TB In TA.OutlineParent.OutlineChildren
            If (TB.Name Like "*fitting*") Or (TB.Name Like "*cmm*") Or (TB.Name Like "*polishing*") Or (TB.Name Like "*edm*") Or (TB.Name Like "*wire cut*") Or (TB.Name Like "*el milling*") Or (TB.Name Like "*milling el*") Then
            TA.LinkPredecessors Tasks:=TB
            End If
        Next TB
        End If

        If (TA.Name Like "*fitting*") Then
        For Each TB In TA.OutlineParent.OutlineChildren
            If (TB.Name Like "*cmm*") Or (TB.Name Like "*polishing*") Or (TB.Name Like "*edm*") Or (TB.Name Like "*wire cut*") Or (TB.Name Like "*el milling*") Or (TB.Name Like "*milling el*") Then
            TA.LinkPredecessors Tasks:=TB
            End If
        Next TB
        End If

        If (TA.Name Like "*cmm*") Then
        For Each TB In TA.OutlineParent.OutlineChildren
            If (TB.Name Like "*polishing*") Or (TB.Name Like "*edm*") Or (TB.Name Like "*wire cut*") Or (TB.Name Like "*el milling*") Or (TB.Name Like "*milling el*") Then
            TA.LinkPredecessors Tasks:=TB
            End If
        Next TB
        End If

        If (TA.Name Like "*polishing*") Then
        For Each TB In TA.OutlineParent.OutlineChildren
            If (TB.Name Like "*edm*") Or (TB.Name Like "*wire cut*") Or (TB.Name Like "*el milling*") Or (TB.Name Like "*milling el*") Then
            TA.LinkPredecessors Tasks:=TB
            End If
        Next TB
        End If

        If (TA.Name Like "*edm*") Then
        For Each TB In TA.OutlineParent.OutlineChildren
            If (TB.Name Like "*wire cut*") Or (TB.Name Like "*el milling*") Or (TB.Name Like "*milling el*") Then
            TA.LinkPredecessors Tasks:=TB
            End If
        Next TB
        End If

        If (TA.Name Like "*el milling*") Or (TA.Name Like "*milling el*") Then
        For Each TB In TA.OutlineParent.OutlineChildren
            If (TB.Name Like "*el design*") Or (TB.Name Like "*design el*") Then
            TA.LinkPredecessors Tasks:=TB
            End If
        Next TB
        End If

        If (TA.Name Like "*wire cut*") And Not TA.Name = "cam wire cut" Then
        For Each TB In TA.OutlineParent.OutlineChildren
            If (TB.Name Like "*cam wire cut*") Or (TB.Name Like "*cam wire*") Then
            TA.LinkPredecessors Tasks:=TB
            End If
        Next TB
        End If

    Next TA

Not (TA.UniqueID = 2 Or TA.UniqueID = 3) 与其他测试一起使用以跳过 UniqueID = 2 或 3 的任务:

Sub AutoPredecessorRepairLevel3()

    Dim TA As Task
    Dim TB As Task

    For Each TA In ActiveProject.Tasks
        If Not (TA.UniqueID = 2 Or TA.UniqueID = 3) And (TA.Name Like "*report*") Then
            For Each TB In TA.OutlineParent.OutlineChildren
                If Not (TB.UniqueID = 2 Or TB.UniqueID = 3) And ((TB.Name Like "*fitting*") Or (TB.Name Like "*cmm*") Or (TB.Name Like "*polishing*") Or (TB.Name Like "*edm*") Or (TB.Name Like "*wire cut*") Or (TB.Name Like "*el milling*") Or (TB.Name Like "*milling el*")) Then
                    TA.LinkPredecessors Tasks:=TB
                End If
            Next TB
        End If

        '....

    Next TA

End Sub