M
MWE
I am running MSProject2000 under WinXP. I recently ran into a problem with
the "Count" value in an MSProject VBA application. The value for
Activeproject.Tasks.Count is NOT the number of tasks. Rather it is the
highest ID number in the current collection of tasks. Thus if you have real
tasks in rows 1 through 10, and 12 through 20, and use row 11 as a separator
row with no data in it, Activeproject.Tasks.Count = 20 but there is no task
#11. If your code sequences through the 20 tasks, execution stops with an
"Object Variable Not Set" error. You have the same problem whether you use
a traditiional index, for example:
Dim I as Integer
For I = 1 to ActiveProject.Tasks.Count
... some code relating to Tasks(I) ...
Next I
or the For Each approach, for example:
Dim ThisTask As Task
For Each ThisTask In ActiveProject.Tasks
... some code relating to ThisTask ...
Next ThisTask
I am sure that others have encountered this problem. Using error
trapping code to test for the existence a task works, but is a bandaid. Is
there a better way to approach this problem?
Thanks
the "Count" value in an MSProject VBA application. The value for
Activeproject.Tasks.Count is NOT the number of tasks. Rather it is the
highest ID number in the current collection of tasks. Thus if you have real
tasks in rows 1 through 10, and 12 through 20, and use row 11 as a separator
row with no data in it, Activeproject.Tasks.Count = 20 but there is no task
#11. If your code sequences through the 20 tasks, execution stops with an
"Object Variable Not Set" error. You have the same problem whether you use
a traditiional index, for example:
Dim I as Integer
For I = 1 to ActiveProject.Tasks.Count
... some code relating to Tasks(I) ...
Next I
or the For Each approach, for example:
Dim ThisTask As Task
For Each ThisTask In ActiveProject.Tasks
... some code relating to ThisTask ...
Next ThisTask
I am sure that others have encountered this problem. Using error
trapping code to test for the existence a task works, but is a bandaid. Is
there a better way to approach this problem?
Thanks