EPMFAQ Forums - Connect with the EPM Community  

Go Back   EPMFAQ Forums - Connect with the EPM Community > Microsoft Project Forums > Project 2007 Development


Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-02-2008, 04:54 PM
Junior Member
 
Join Date: Sep 2008
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Post Windows Forms Application - Opening MS Project 2007

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.








Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored links
  #2 (permalink)  
Old 09-15-2008, 08:42 AM
ssanderlin's Avatar
EPMFAQ Founder/Owner
 
Join Date: Feb 2008
Location: Quakertown, PA
Posts: 161
Thanks: 0
Thanked 13 Times in 13 Posts
Default

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 View Post
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -4. The time now is 04:45 PM.


Powered by: vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
Ad Management by RedTyger

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24