Project application objects in VBA and other office apps

G

Gilgamesh

Hello,
I know how to create project objects within (for example MS Word) and
access project items appropriately with code like this.
Dim oProj as Object
Set oProj = CreateObject("MSProject.application")
oProj.FileOpen Name="File.mpp"
MsgBox (oProj.ProjectSummary.Name)
etc

When I do this the project object is invisible and all I see is the word
windows, this is what I want.


However when I tried doing the same inside MS Project VBA it doesn't work.
I know I can open multiple files in the application and switch between them
but for what I want to do I need to reference multiple files simultaneously
(Plus opening the files normally makes them visible).

Can anyone help with how to create further project application objects
within project VBA?

Thank You
 
G

Gilgamesh

Gilgamesh said:
Hello,
I know how to create project objects within (for example MS Word) and
access project items appropriately with code like this.
Dim oProj as Object
Set oProj = CreateObject("MSProject.application")
oProj.FileOpen Name="File.mpp"
MsgBox (oProj.ProjectSummary.Name)
etc

When I do this the project object is invisible and all I see is the word
windows, this is what I want.


However when I tried doing the same inside MS Project VBA it doesn't work.
I know I can open multiple files in the application and switch between
them but for what I want to do I need to reference multiple files
simultaneously (Plus opening the files normally makes them visible).

Can anyone help with how to create further project application objects
within project VBA?

Thank You

I should have mentioned that I'm using Project 2003 :)
 
J

Jack Dahlgren

Project does not allow you to have multiple instances of the application. It
is different from word and excel in this regard. You can still reference
multiple projects though.

application.projects

refers to the projects collection and you can work with any or all of them.

the .visible property will control whether they are visible or not.

-Jack Dahlgren
 
G

Gilgamesh

Martin Winzig said:
what about folowing magic line ?


oProj.visible=true

Which doesn't help with the original question about opening multiple
objecrts :)
However Jack's answer addresses that.
 
G

Gilgamesh

Jack Dahlgren said:
Project does not allow you to have multiple instances of the application.
It is different from word and excel in this regard. You can still
reference multiple projects though.

application.projects

refers to the projects collection and you can work with any or all of
them.

the .visible property will control whether they are visible or not.

-Jack Dahlgren

Hello,
I've been playing around with the collections as suggested but I'm having
some problems.

I have noticed that when I open the MS project application and then open the
file with my macros in it, then the collection I have to refer to is number
2 for the project with my macros in it
But if I douple click on this file which then opens the MS Project
application the collection number is 1.
In both cases the Application.Projects.Count value was 1.
I know that I can refer to specific projects using their name rather than
the number but I'm curious as to the reason for this.

When I looked at the projects collection there was no .visible property - I
found this under the windows collection so I think this is OK.

Now to the important questions.
1) If I use Application.Projects.Add to get a new blank project is there any
way of determining its number so I can use it.
I could try and use Application.Projects.Count but given the number
descrepancy I described above I wouldn't know the correct number to use.
2) Using the projects collection is there any way of closing an instance
(with and without saving the file) without having to make the make the
window active first and then using FileClose.

Thank You
 

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