title: Assigning Task.Duration to an already added Task in VBA Microsoft Project
body: <p>I'm currently working on a VBA macro importing product-requirements into Microsoft Project.  </p>
  
  <p>I use the following code for adding/updating a task:</p>
  
  <pre><code>Function AddTask(strText As String, lngDuration As Long, taskParent As Task)
      Dim oldTask As Task
      Set oldTask = taskParent.OutlineChildren(strText)
      If oldTask Is Nothing Then
          Dim newTask As Task
          Set newTask = taskParent.OutlineChildren.Add(Name:=strText, Before:=LastIndexOf(taskParent) + 1)
          newTask.OutlineLevel = taskParent.OutlineLevel + 1
          newTask.Duration = lngDuration
          Set AddTask = newTask
      Else
          oldTask.Duration = lngDuration
          Set AddTask = oldTask
      End If
  End Function
  </code></pre>
  
  <p>This works perfectly for a new task, but unfortunately I get a weird error when trying to update the Duration property on an old task.</p>
  
  <pre><code>Run-Time Error '1101'
  
  Argument value is not valid
  </code></pre>
  
  <p>I really don't understand what the difference between</p>
  
  <pre><code>newTask.Duration = lngDuration
  </code></pre>
  
  <p>and</p>
  
  <pre><code>oldTask.Duration = lngDuration
  </code></pre>
  
  <p>What's going on here?<br>
  Please help!</p>