locked
Debug VBA script that removes resources while keeping costs for MS Project RRS feed

  • Question

  • Sub SanitizeProject()
     
     Dim R As Assignment
     Dim T As Task 
     Dim TempD As Long
     Dim TempAC As Double
     Dim TempRC As Double
     Dim TempC As Double
     Dim answer As Integer
     
     answer = MsgBox("Would you also like to remove costs?", vbQuestion + vbYesNo + vbDefaultButton2, "Question")
     
     
     For Each T In ActiveProject.Tasks
     TempD = T.Duration
     TempPC = T.PercentComplete
     TempAC = T.ActualCost
     TempRC = T.RemainingCost
     TempC = T.Cost
        For Each R In T.Assignments
            R.Delete
        Next R
     
     T.Duration = TempD
     T.PercentComplete = TempPC
     T.Cost = TempC
     If answer = vbYes Then T.Cost = 0 Else T.Cost = TempC
     Next T
     
    End Sub
    I always get a "Run-time error '91': Object variable or With block variable not set" where I set the Temp variables. Running it on a different project, I also get a "Run-time error '1101': The argument value is not valid on the line T.Cost = TempC. Can someone help with this?
    • Edited by rogue844 Thursday, November 12, 2020 9:45 PM
    Thursday, November 12, 2020 9:36 PM