Task Iteration in VB.NET

J

Jim Aksel

In Visual Stduio 2005, I have a program that will open MS Project2007 and two
files (Source.mpp & Target.mpp)
I am receiving a COM conversion error-- Unable to cast object of type
System._ComObject to type Microsoft.Office.Interop.MSProject.Task. Here is a
code snippet-

Dim tsk as Microsoft.Office.Interop.MSProject.Task
Dim SourceID as integer
pjApplication.FileOpenEx(SourceFile) 'Sourcefile = "C:\Source.mpp"
SourceID=pjAppllication.ActiveProject.Index 'Integer of mpp file in Window
of Project

For each tsk in pjApplication.Projects.Item(SourceID).Tasks <<<Error is here
'more code here
Next tsk

Using the debugger, tsk appears to have the value Nothing, SourceID is fine
at 1. So it appears I am not assigning tsk properly.

Any guidance to eliminate this error would be helpful. I am referencing
Office12.0 and Project12.0 libraries.

--
If this post was helpful, please consider rating it.

Jim
It''s software; it''s not allowed to win.

Visit http://project.mvps.org/ for FAQs and more information
about Microsoft Project
 
J

Jan De Messemaeker

AFAIK you must have a blank line within the tasks you read.
Eliminate it and you'll be fine.
HTH
 
J

Jim Aksel

It crashes prior to reading the first line. There are no blank lines in the
file and I have also tried turning on the summary task. Let me know if you
think of anything else. In the meantime, I'll post whatever else I learn.

Jim
 
J

Jan De Messemaeker

Hi,

Let me try again
Problem is I don't know all this Interop stuff so this is just a guess.
Isn't it simpler hence more secure to use

For each tsk in pjApplication.activeproject.Tasks

(At least this make sure you're not refeering to a blank Project1)

Hoppe this helps,
 

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