.Net PIA project.Activate() Method - Get Out of Jail Free Card Inc

S

Seawolf

Hi all,

I’ve saw the MS Project project.Activate() method problem come round the
block again last month and I apologize for not writing this earlier. The
Activate() problem seems to be a frequent flier and since I haven’t seem a
solution write up, I thought I’d put this up on the board.

I have a full C# test frame for this to prove both the problem and solution,
pm me if anyone needs a copy and I’ll oblige.

Problem.

..Net application using the project.Activate() method raises the following
exception:

An unexpected error occurred with the method.

This problem denies access to .Activeproject specific methods such as
FileClose.

Cause.

The application.Visible property has not been set to true at least once.

Use Case:

private Microsoft.Office.Interop.MSProject.Application projectServer = new
Microsoft.Office.Interop.MSProject.Application();

projectServer.Visible=false;

Pseudo code..

- Open “ProjectOneâ€;
- Open “ProjectTwoâ€;
- Open “ProjectThreeâ€;
-
- all method calls to project.Activate() will fail:

projectServer.Projects[“ProjectOneâ€].Activate();
or
projectServer.Projects[1].Activate();

However if the projectServer.Visible property is now set to true, the above
method calls will now work. However the MS Project application will briefly
flash on screen which may be an unwanted result.

Conclusion:

Initialization code exists in the Visible=true property assignment that
otherwise is not invoked.

Alternatives:

Use the Windows collection (recommended), this has the same functionality
and performs correctly regardless of the .Visible property setting.

projectServer.Windows[“ProjectOneâ€].Activate();
or
projectServer.Windows[1].Activate();

Use Windows API functionality to trace the MS Project application process
and it’s primary container window and control visibility via WM_Messages.
This option has not been tested yet and is not recommended unless a high
level of application control is required.

On a final note, if you are using the .Project.Activate() method with
visible instances of MS project you will get an ambiguity warning since
..Activate is implemented as both a method and event in the PIA. To resolve
this cast appropriatly :

..Project.Activate() – Will report an ambiguity warning and potential
wierdness.

((msProject._IProjectDoc)projectObject).Activate() – Will not.

Good luck, Lee.
 

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