I'm currently working on a VBA macro importing product-requirements into Microsoft Project.
I use the following code for adding/updating a task:
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
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.
Run-Time Error '1101'
Argument value is not valid
I really don't understand what the difference between
newTask.Duration = lngDuration
and
oldTask.Duration = lngDuration
What's going on here?
Please help!