How can I open a Project file (mpp) invisibly all the time?

R

Rotem

I am using the following code to "silently" open a project file:

Set pjApp = CreateObject("MSproject.Application")
pjApp.DisplayAlerts = False
pjApp.Visible = False
pjApp.FileOpen Name:=strFileNameToOpen, ReadOnly:=True
Set pjDoc = pjApp.ActiveProject

It works fine if no project file was open previously (Project is running).
However, if Project was running before (anointer file was open an visible to
the user) file (strFileNameToOpen ) is displayed anyway.

Is it possible to always open a file with Project "silently" (not visible to
the user)?
e.g. like in Excel or word.
 
J

John

Rotem said:
I am using the following code to "silently" open a project file:

Set pjApp = CreateObject("MSproject.Application")
pjApp.DisplayAlerts = False
pjApp.Visible = False
pjApp.FileOpen Name:=strFileNameToOpen, ReadOnly:=True
Set pjDoc = pjApp.ActiveProject

It works fine if no project file was open previously (Project is running).
However, if Project was running before (anointer file was open an visible to
the user) file (strFileNameToOpen ) is displayed anyway.

Is it possible to always open a file with Project "silently" (not visible to
the user)?
e.g. like in Excel or word.

Rotem,
In that regard Project is different from Excel. Excel will allow several
instances to be opened simultaneously. Project however is limited to one
instance, although several project files can be opened simultaneously.

I'm not sure why you would want to covertly open a project file, but to
do so you will need to detect it Project is already open. If not, then
start Project and open the file in the background. If Project already is
open, then just open the file of interest in the background.

Hope this helps.
John
Project MVP
 
R

Rotem

--
S. Rotem


John said:
Rotem,
In that regard Project is different from Excel. Excel will allow several
instances to be opened simultaneously. Project however is limited to one
instance, although several project files can be opened simultaneously.

I'm not sure why you would want to covertly open a project file, but to
do so you will need to detect it Project is already open. If not, then
start Project and open the file in the background. If Project already is
open, then just open the file of interest in the background.

Hope this helps.
John
Project MVP

Hi John
Sounds fair, but how do I detect if MSP is running and if so how do I open a
file in the background?
Thanks :)
Rotem
 
G

Gérard Ducouret

Rotem,

To check if MS Project is already running:

Sub Test_MSP()
Dim dejala As Boolean '("dejala" means "already there" in French ;-)
dejala = IsAppRunning2("MSProject.Application")
If dejala = True Then
MsgBox "MSP is running"
Else
MsgBox "Nothing there"
End If
End Sub

Public Function IsAppRunning2(ByRef StrApp As String) As Boolean
'Checks if the passsed application is already running
Dim objApp As Object
On Error Resume Next

Set objApp = GetObject(, StrApp)
IsAppRunning2 = (Err.Number = 0) 'True si err.Number = 0 donc pas d'erreur :
l'application est bien ouverte
Set objApp = Nothing
Err.Clear 'Vide toutes les valeurs de propriété de l'objet Err.

End Function

hope this helps,

Gérard Ducouret
 
R

Rotem

Dear Gerard

Your code sample for the "App is running?" is very nice. Unfortunately the
difficult task I still do not now how to solve regards the – How to run a MSP
file in the background of things. Is it possible?
 
G

Gérard Ducouret

Rotem,

Try to use the "Visible" property :
Set App = CreateObject("MSProject.Application")
App.Visible = False

Gérard Ducouret
 
J

John

Hi John
Sounds fair, but how do I detect if MSP is running and if so how do I open a
file in the background?
Thanks :)
Rotem

Rotem,
It looks like Gerard answered your question. Just curious, what is your
end goal? That is, why are you trying to run Project covertly?

John
Project MVP
 
R

Rotem

Hi John (and Gerard)
As you can see in my original RFH (Request For Help)
pjApp.Visible = False
has no influence (surprisingly) if Project is already in use (running) with
another file that was previously opened.

Regarding your question:
I am building an application to collect Costume properties from files of
different origins (one of them is MSP).
According to my understanding (and experience) it is only possible to be
done through an open file.
e.g.:
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Open FileName:=strFileNameToOpen
Set xlDoc = xlApp.Workbooks(1)
Set colCustomProperties = xlDoc.CustomDocumentProperties
 
J

John

Rotem said:
Hi John (and Gerard)
As you can see in my original RFH (Request For Help)
pjApp.Visible = False
has no influence (surprisingly) if Project is already in use (running) with
another file that was previously opened.

Regarding your question:
I am building an application to collect Costume properties from files of
different origins (one of them is MSP).
According to my understanding (and experience) it is only possible to be
done through an open file.
e.g.:
Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Open FileName:=strFileNameToOpen
Set xlDoc = xlApp.Workbooks(1)
Set colCustomProperties = xlDoc.CustomDocumentProperties

Rotem,
In a quick test I performed, using the Visible Property effectively does
the same thing as minimizing the window. However, according to the VBA
help file, setting the Visible Property to false can only be done by the
same user who opened Project.

If all you want to do is to get a file's custom (I assume you really
don't mean "costume") properties, I suggest you just open the file in
the foreground, get the info and then close without saving.

John
Project MVP
 
R

Rotem

Diear John

I didn't really understand what you meant by – does the same … window. – I
am using window XP and VB6 and if I run the code I mentioned, I get a new
window exactly as the already open one.

Regarding the custom Properties (sorry for my English), you are right. To
only retrieve custom properties, one can use a very helpful tool that can be
found in http://support.microsoft.com/kb/224351. I for a change, have to open
many files at ones to retrieve a lot of data for manipulation. It will
certainly confuse the user of the program if he will see this activity (with
should be normally run in the background).

I must say that in all the other applications I was working with in the
past, setting object.Visible was having a different affect (as expected)
maybe the problem with MSP is a bug of Microsoft?

Thanks a lot,
S. Rotem
 

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