Assigning a valid reference to object type 'Task'

D

draco664

Greetings all,

I've been asked to write a macro that will collate certain information
from various fields (custom defined and normal) from our projects for
statistical analysis.

Things like, sum of all values in Number5, the median average of all
values in Actual Cost, a list of all the different values in Text2,
that sort of thing.

Scope creep however is a problem. Every time I present the results, I
get told that it's great, but could I add another thing please?

Currently, I'm using arrays of type string or long or date to gather
and manipulate this data, but every time I get anothe request, I have
to add another array, and the macro's declaration section is beginning
to approach novella length.

I tried to use an array of type 'Task', thinking that I could use the
one array to store all this data (not to mention not having to create
new arrays all the time, just use new properties of the same data
type.

The problem is that I can't work out how to initialise the new array
of Tasks. I was getting error 91 (object variable not set), but there
was no information in help about how to set a variable of type 'Task'.
The one thing in help that was, well, helpful was a line that said
that 'you must assign a valid reference to the object variable using
the Set statement'. However, I can't find anything that shows how to
use the Set statement on a variable of type 'Task'.

Any suggestions?

Thanks in advance,

Chris
 
R

Rod Gill

Hi,

Please post VBA questions in the project.programming group in future.

Try:

Sub test()
Dim Tsks(1 To 2) As Task
Set Tsks(1) = ActiveProject.Tasks(1)
Set Tsks(2) = ActiveProject.Tasks(2)
MsgBox Tsks(2).Name
End Sub

Another thing to try is to read and export the data to a database where it
can be reported on or to Excel.

--

Rod Gill
Microsoft MVP for Project

Author of the only book on Project VBA, see:
http://www.projectvbabook.com
 
D

draco664

Hi,

Please post VBA questions in the project.programming group in future.

Shall do. Thanks for the tip.
Try:

Sub test()
Dim Tsks(1 To 2) As Task
Set Tsks(1) = ActiveProject.Tasks(1)
Set Tsks(2) = ActiveProject.Tasks(2)
MsgBox Tsks(2).Name
End Sub

I'll give it a go. Thanks.

I bought your book on project VBA. Very easy to read and understand.

Thanks,

Chris
 
M

Mike Glen

Hi ,

Just for the record, the project programming group is called
microsoft.public.project.developer newsgroup. Please see FAQ Item: 24.
Project Newsgroups. FAQs, companion products and other useful Project
information can be seen at this web address:
http://project.mvps.org/faqs.htm

Mike Glen
Project MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top