Results 1 to 3 of 3

Thread: Windows Forms and opening MS Project.mpp File

  1. #1
    Join Date
    Nov 2006
    Posts
    3

    Windows Forms and opening MS Project.mpp File

    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.

  2. #2
    Join Date
    May 2008
    Posts
    188
    For Each mTask In mTasks 'pjApplication.ActiveProject.Tasks
    'the real work goes here
    Next mTask
    I have seen your code and I didn't find any statement where you have assigned anything to mTask. So how can you run the For loop if nothing is assigned to it. For loop need some value to run the statements in it.

  3. #3
    Join Date
    Nov 2006
    Posts
    3
    Yes, that is my question ... what line of code do I need to assign something to mTask?

    mTask is dimensioned, and is set to null. I need to be able to iterate through the mTasks collection. Doing it this way works fine in VBA, but I am missing the secret line of code that will initialize mTask to something even though it is of type Task.

Similar Threads

  1. Replies: 18
    Last Post: 16-06-2012, 06:36 AM
  2. MS Project 2010 does not work after opening a mpp-file
    By Kane in forum Microsoft Project
    Replies: 5
    Last Post: 21-03-2012, 03:18 PM
  3. Internet explorer web file is not opening in windows 7
    By ZiGmA4321 in forum Windows Software
    Replies: 3
    Last Post: 17-01-2011, 06:08 PM
  4. How to open a MS project 2007 file in MS project 2010
    By pqmot in forum Windows Software
    Replies: 3
    Last Post: 30-12-2010, 04:41 PM
  5. Replies: 3
    Last Post: 10-11-2010, 07:27 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,748,736.09845 seconds with 16 queries