How to call MS Project 2003 from vb.net 2005?

U

urgent!!

I've added the reference to Microsoft Project 11.0 Object Library which path
is C:\Program Files\Microsoft Office\OFFICE11\MSPRJ.OLB. After referenced
I've get Microsoft HTML Object Library, Microsoft Office 11.0 Object Library,
Microsoft Project 11.0 Object Library and Microsoft Visual Basic for
Applications Extensibility 5.3. Below are my codes:

Dim theFile As String
OpenFileDialog1.InitialDirectory = Application.ExecutablePath
OpenFileDialog1.DefaultExt = "mpp" 'custom format
OpenFileDialog1.FileName = ""
OpenFileDialog1.Filter = "Microsoft Project Files" _
& " (*.mpp)|*.mpp"
OpenFileDialog1.ShowDialog()
theFile = OpenFileDialog1.FileName

Dim pj As New MSProject.Application
pj.Visible = True
pj.FileOpen(theFile)
Debug.Print(pj.ActiveProject.Name)
Debug.Print(pj.ActiveProject.Tasks.Count)
Dim tsk As MSProject.Application
For Each tsk In pj.ActiveProject.Tasks
Debug.Print(pj.ActiveProject.Name)
Next

If i replace the line "Dim pj As MSProject.Application" with
"Microsoft.Office.Interop.MSProject.Application", it is highlighted with blue
line saying Microsoft.Office.Interop.MSProject.Application is not defined.
But if no changes, I get error during runtime. I've used OpenFileDialog to
get the Project file which is at dekstop.
 
J

Jim Aksel

Sorry, I don't have a VS machine here to assist further. Perhaps when I get
home.
Your code looks fine butobviously there's an error lurking somewhere.
 
R

Rod Gill

Of course you can code directly in VB.Net, but you will almost certainly get
at least a dozen bugs with no knowledge of what your main problem is. By
coding in VBA first you get all Project Object problems sorted in an easy to
code environment, then you copy the working code to VB.Net. It will be
significantly faster this way and if you really have a tight deadline you
will have to use this method. Even if I was coding in VB.Net I would only
copy code I knew worked in VBA first.

--

Rod Gill
Project MVP

Project VBA Book, for details visit:
http://www.projectvbabook.com

NEW!! Web based VBA training course delivered by me. For details visit:
http://projectservertraining.com/learning/index.aspx
 

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