
09-15-2008, 08:42 AM
|
 | EPMFAQ Founder/Owner | | Join Date: Feb 2008 Location: Quakertown, PA
Posts: 169
Thanks: 0
Thanked 13 Times in 13 Posts
| |
I don't know why it's erroring out like that... Have you tried using a regular for loop instead of foreach? Quote:
Originally Posted by jimaksel I am developing a Windows Forms application in VB.NET using Visual Studio 2008. I am attempting to open an MSProject.mpp file and iterate through the tasks. Here is my code from Form1 so far:
Dim mFileName As String
'When looking at the project Window drop down, determine the index number of the file
Dim iFileIndex As Int16
Dim pjApplication As New Microsoft.Office.Interop.MSProject.Application
Dim mTasks As Microsoft.Office.Interop.MSProject.Tasks
Dim mTask As Microsoft.Office.Interop.MSProject.Task
'Get an mpp file, no error checking at this time
OpenFileDialog1.ShowDialog()
mFileName = OpenFileDialog1.FileName.ToString()
TextBox1.Text = mFileName.ToString
pjApplication.FileOpen(mFileName) 'FileOpenEx(SourceFile) ????
pjApplication.Visible = True
pjApplication.AppMinimize()
Debug.Print("File Opened: " & mFileName.ToString)
iFileIndex = pjApplication.ActiveProject.Index
Debug.Print("Active Project: " & pjApplication.ActiveProject.Name.ToString)
mTasks = pjApplication.ActiveProject.Tasks
Debug.Print("Task Count: " & mTasks.Count.ToString)
Debug.Print("Source File Index: " & iFileIndex.ToString & " Task Count: " & mTasks.Count)
'************************************************* *******
'This is where it dies: it tells me mTask is set to "Nothing" What do I need??
'************************************************* ********
For Each mTask In mTasks 'pjApplication.ActiveProject.Tasks
'the real work goes here
Next mTask
So it does not like the For Each loop for some reason. It is the mTask that seems to be doing it. All the Debug.Print statements return expected values. |
__________________ Stephen Sanderlin
Founder/Owner - EPMFAQ
Principal Consultant - MSProjectExperts If you found this message useful, please click the Thanks button in the post!
This electronic message, along with any information, advice, and opinions it contains, are mine alone and are not representative of my employer. All information is provided in "GOOD FAITH" and on an "AS IS" basis only. I provide no presentations or warranties, express or implied, including implied warranties of fitness for a particular purpose, merchantability, title, and noninfringement. I strongly advise you to extensively test any changes, workarounds, or techniques described herein on a development system prior to implementation in a production environment, and you are hereby notified that I bear no responsibility whatsoever for any loss, harm, or otherwise negative outcomes resulting from your actions, whether or not said actions were a result of this electronic message, directly or indirectly. |