Question

I am trying to open a PowerPoint presentation, and have it hidden. I am doing it this way:

app = new Microsoft.Office.Interop.PowerPoint.Application();
string presentation = "C:\\presentation.pptx";

Presentation p = app.Presentations.Open(presentation, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);

It is the simplest thing, yet I receive an error saying:

Application (unknown member) : Invalid request. There is no active presentation.

However, if I switch the last parameter (which is the WithWindow parameter) to MsoTriState.msoTrue, the presentation opens fine.

Was it helpful?

Solution 2

Do you have any other add-ins that might be causing that error? I ran your code (from VBA) and it ran fine.

OTHER TIPS

The code provided in the question works correctly, but there is an important note:

In C# you have to leave Application.Visible property with it's default value:

var application = new Application();
var document = application.Presentations.Open(fileName, MsoTriState.msoFalse, MsoTriState.msoFalse, 
    WithWindow: MsoTriState.msoFalse);

If you explicitly set Application.Visible property to MsoTriState.msoFalse you will get "Hiding the application window is not allowed" error.

I've tried this one, and it works:

Presentation p = app.Presentations.Open(presentation,0, 0, 0);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top