question

mDCX-8028 avatar image
0 Votes"
mDCX-8028 asked

How to import Excel data into Microsoft Project subtasks using VBA

Hi,

So I have an Excel file with five date fields, a task name, and unique task number. I import the data into Project using the import wizard to map the Task name > Task Name, Unique ID > Number1, StartDate > Date1, EndDate > Date 2. I then use the following macro to add the same three subtasks to each parent task:

Sub InsertSubTasks()

 Dim tsk As Task
 For Each tsk In ActiveProject.Tasks
     If tsk.Flag1 And tsk.OutlineChildren.Count = 0 Then
         With ActiveProject
             .Tasks.Add "Subtask 1", tsk.ID + 1
             .Tasks.Add "Subtask 2", tsk.ID + 2
             .Tasks.Add "Subtask 3", tsk.ID + 3
                
             .Tasks(tsk.ID + 1).OutlineIndent
             .Tasks(tsk.ID + 2).OutlineIndent
             .Tasks(tsk.ID + 3).OutlineIndent
         End With
     End If
 Next tsk

End Sub

This works. But now I need to import the data from the three remaining date fields to each subtask. So for Unique ID A I would link its Date 3 to Subtask 1, Date 4 to Subtask 2, and Date 5 to Subtask 3. I need to do this for the subtasks of each parent task. Does anyone know how I can expand on this code to import the dates from Excel to the Project subtasks?

office-vba-dev
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers