Wait for MS Project to close

T

Taras Pich

I have an application that tracks project information.
It allows the user to open an MS Project file when the application is
selected.
What code do I need to include to suspend the sub from continuing until the
MS Project application is closed?
Right now it opens the project OK but continues on and immediately closes
it.

TIA,
Taras
 
S

Shailesh [MVP]

if u r using Process.Start to start ms project, then it would return u the
Process object like this.

Process p = Process.Start("msproject");
p.WaitForExit();

The second call will suspend the execution till the process exits.

Thanks.
Shailesh
 
T

Taras Pich

Shailesh
Your reply works but only part way.
I was previously using the following code which would open the file
properly - but it didn't halt the process
'sMPP contains full path\filename info & is valid
pjApp = CreateObject("MSProject.Application")
pjApp.Visible = True
lPjPlan = pjApp.FileOpen(sMPP, False, , , , , , , , , ,
MSProject.PjPoolOpen.pjPoolReadOnly)

When I try your solution
Dim pPROJ AS PROCESS
pPROJ = PROCESS.START("WINPROJ.EXE", sMPP)
I get a message from Project stating it can't recognize the file - same
thing happens if I put in text.

Trying other combinations of Process.x results in the same thing.

Any further ideas? I have to open Project with the specified file name.

TIA
Taras
 
S

Shailesh [MVP]

two things...
1. try giving full path to winproj.exe
2. enclose all the paths in parameter in double quotes. so that means if you
winproj.exe is in c:\msproject\
and your project file mpp file is in c:\my documents\a.mpp then try like
this.

string pathtoproject = @"c:\msproject\winproj.exe";
string pathtompp = @"c:\my documents\a.mpp";
ProcessInfo p = new ProcessInfo(pathtoproject, pathtompp);
Process myprocess = Process.Start(p);
myprocess.WaitForExit();

this will work only if msproject is accepting mpp as argument and opens it
like word.

HTH.
Shailesh
 
T

Taras Pich

Shailesh,
String pathtoproject=@"c:\" is not valid in vb.net. That and any other
command line results in the @ being flagged as "Character not valid"

I don't think I can really put a path in to winproj since I have no control
over where it may be on any PC, short of searching for it and then building
the path from there - which I may end up having to do.

Path and file are obtained from 2 databases so I create the pathtoproject as
sMPP = sPrjPath & dgProjRow(19) & ".MPP"

So how do I get the @variable



Thanks
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top