Answered by:
Looping through Summary Tasks in VBA

Question
-
I have built a VBA module to loop through and update summary tasks but it goes through every task and checks to see if its a summary task then performs the action I need. My issue is this is becoming slow since I have almost 4,000 tasks in the schedule. Is there a way I can loop through the summary tasks only (There is only about 300 summary tasks) to speed up the VBA module?Thursday, May 18, 2017 12:39 PM
Answers
-
Try:
- Apply the filter Summary Tasks
- Select all tasks
- Loop thru selected tasks only
- re-apply original filter (or All tasks filter)
Something like:
Sub Test()
Dim OldFilter As String
Dim OldId
Dim Tsk As Task
OldFilter = ActiveProject.CurrentFilter
OldId = ActiveCell.Task.ID
FilterApply "Summary Tasks"
For Each Tsk In ActiveSelection.Tasks
If Tsk.Summary Then
'Do your update
End If
Next Tsk
FilterApply OldFilter
EditGoTo ID:=OldId
End SubRod Gill
Author of the one and only Project VBA Book and VBA developer.
www.project-systems.co.nz- Proposed as answer by John - Project Wednesday, May 24, 2017 2:24 PM
- Marked as answer by pd240 Thursday, May 25, 2017 9:03 PM
Wednesday, May 24, 2017 2:51 AM
All replies
-
Try:
- Apply the filter Summary Tasks
- Select all tasks
- Loop thru selected tasks only
- re-apply original filter (or All tasks filter)
Something like:
Sub Test()
Dim OldFilter As String
Dim OldId
Dim Tsk As Task
OldFilter = ActiveProject.CurrentFilter
OldId = ActiveCell.Task.ID
FilterApply "Summary Tasks"
For Each Tsk In ActiveSelection.Tasks
If Tsk.Summary Then
'Do your update
End If
Next Tsk
FilterApply OldFilter
EditGoTo ID:=OldId
End SubRod Gill
Author of the one and only Project VBA Book and VBA developer.
www.project-systems.co.nz- Proposed as answer by John - Project Wednesday, May 24, 2017 2:24 PM
- Marked as answer by pd240 Thursday, May 25, 2017 9:03 PM
Wednesday, May 24, 2017 2:51 AM -
pd,
If you are going to use Rod's excellent code directly, then you'll want to insert "SelectAll" just in front of the For statement. Always the teacher, he's giving you something to think about....
Wednesday, May 24, 2017 2:34 PM -
pd240,
I'm curious, summary lines are not tasks but rather a summary of the subtask data under them. So what exactly are you "updating" about the summary lines?
John
Wednesday, May 24, 2017 6:44 PM -
Thanks Rod - That solution worked.
John - I have VBA code that grabs information from an access database and brings it into the project file but I only need the data at the summary task level. Some of the data I do need at the individual task level for reporting but for those I run a seperate module through the entire project to fill down the custom fields of the child tasks.
- Edited by pd240 Thursday, May 25, 2017 9:04 PM
Thursday, May 25, 2017 9:03 PM -
pd240,
That makes sense if the data from Access is for custom fields at summary level.
John
Friday, May 26, 2017 1:50 AM