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

U

urgent!!

hi, I'm having difficulty in calling a MS Project 2003 file using vb.net
2005. I'm new to this so if possible could you teach me the steps to achieve
it. Basically I wan to call the MS Project file so that I can retrieve the
data for every column and display it in my vb.net program. If necessasry
changes will be made to the data as well. I really need guidance from you
guys. Thanks.

KY
 
A

Adam Behrle

KY,

Search for the Project 2003 SDK and solution starters on MSDN. The
solution starters include a .net Addin written in VB (which will help
even if your writing a seperate applciation). This is if you decide to
go the Project Automation route (probably best way for read/write of
mpp).

For just read-only access to the mpp, check out the Project OLE DB
connection.

Hopefully this gets you started looking in the right places.

Adam
 
S

Scudder

KY, you have 2 options to achieve this:

Design an add-in that start up with MS project and interacts with the
application via the object model.

or

Design a stand alone application that starts MS Project as a (hidden or
visible) server application and interacts via the object model.

Which of these are you attempting to implement ?
 
U

urgent!!

the second one...design a stand alone application that starts MS Project as a
(hidden or visible) server application and interacts via the object model.
Could you please tech me how to achieve it?
 
S

Scudder

Sure I can help you along, a couple of questions though.

Is this your first encounter with the MS Project Object Model ?

...and do you have access to and can program in VB6 ?
 
U

urgent!!

yes, this is the first time I've encounter with the MS Project Object Model.
I've access and program in VB6 before. By the way, I'm using vb.net 2005 not
VB6 and this is the first time I program in vb.net 2005.
 
R

Rod Gill

I think you need to get familiar with vb.net before adding Project
functionality. Otherwise neither of us will know where a problem rests. Try
creating the application first and get everything working without the
Project interface. Then you can add the Project part. You have two big
learning curves ahead of you, so knock one of at a time!!

To learn the Project object model, practise by using Project's VBA language.
Much of the code you create can be copied and pasted into VB.Net and made to
work with minimal editing.

--

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
 
U

urgent!!

Basically I'm able to program a simple program using vb.net and I've been
learning it. Also I've don't have much time left so I have no choice but to
directly learned MS Project Object Model. I just want to know how to starts a
MS Project in vb.net and access the columns and rows in MS Project.
 
R

Rod Gill

HI,

Paste this code into Excel VBA and set a reference to Project object
library. Run the code and experiment to get the information you need, then
copy paste into VB.Net and modify. Don't copy until you have working code in
Excel. This code works with the current Project. If you want to do other
things in Project, record a macro in Project and edit the recorded code to
work in Excel.

If you really are in a hurry, my book is the only one on Project VBA and
will give you a great headstart, including controlling Project from Excel.

--

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
 
S

Scudder

~ Challenging if you have a tight deadline. You are a VB.Net beginner and are
new to the MS Project Object Model. I'd take Rod's advice if I were you.

If you are just after the results, can't you just copy and paste the MS
Project data into Excel to create your graphs as a 'tactical' measure until
you can get your skillset up to speed ?
 
U

urgent!!

I don't understand what you mean by "copy and paste the MS
Project data into Excel to create your graphs as a 'tactical' measure until
you can get your skillset up to speed".
 
S

Scudder

Sorry....wrong thread, you're not alone out there.

I would certainly concentrate on using VBA to achieve your initial results
as Rod advised. I use C# for my MS Project interop but sometimes prototype in
VB6 or VBA just to eliminate some of the .net foibles.

Do you have an outline spec for what you are trying to achieve ?
 
J

Jim Aksel

Working with MS Project in VB.NET is not for the timid.
Start a new VB.NET Solution.
Reference the MS Project library:
Project/Add Reference....
Pull the COM tab and select the Microsoft Project 11.0 Object Library.
Version 11 is Project 2003, version 12 is for Project 2007.

Here is some code that will get you started. You have to make all your own
forms, etc. Again, it is not for the timid.

Dim pj As New Microsoft.Office.Interop.MSProject.Application
pj.Visible = True
pj.FileOpen(txtSourceFile.Text.ToString())
Debug.Print(pj.ActiveProject.Name)
Debug.Print(pj.ActiveProject.Tasks.Count)
Dim tsk As Microsoft.Office.Interop.MSProject.Task
For Each tsk In pj.ActiveProject.Tasks
Debug.Print(tsk.Name)
Next

This code will open an existing file, and print the name, task count, and
the name of each task in the file.

txtSourceFile.Text is the Text property of a TextBox on Form1.vb

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

Jim

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

urgent!!

Thanks for the code but I've encounter an error saying:

Microsoft.Office.Interop.MSProject.Application is not defined

do I need to import anything? Then I've tried change it to
MSProject.Application and I've encounter another error saying:

Unable to cast COM object of type 'System.__ComObject' to interface type
'MSProject.Application'

at line
For Each tsk In pj.ActiveProject.Tasks

How can I resolve this?
 
J

Jim Aksel

I'm not able to reproduce that error with the code provided.
However, make sure you have referenced the correct object library.
In VS2005: Project/Add References... COM Tab.
The referenced file resides in the same folder where you installed MS Project.
You have Project installed on the development machine?

Make sure the source file in txtSourceFile.txt actually exists with no blank
lines and has at least one task.
--
If this post was helpful, please consider rating it.

Jim

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

urgent!!

yes, I have Project installed on my development machine. I've also referenced
correctly. Does the path of the Project file matter? The Project file is
located at dekstop. When I referenced the object by default it is resides in
the same folder where MS Project is installed right?
 
J

Jim Aksel

A visual studio file will search for your .mpp file in the same folder as the
visual studio project exe file. It is usually a BIN or DEBUG folder. So,
no, they are not in the same place.

Bottom line, the file name for your .mpp file needs to be a full path. The
best way to accomplish that is to use an OpenFile Dialog Box. You mentioned
the desktop issue and I try to avoid that favoring a folder like: C:\a\
Using the OpenFileDialog should avoid any desktop file location problems.

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

Jim

Visit http://project.mvps.org/ for FAQs and more information
about Microsoft Project
 
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.
 

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