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.
Do you have any other add-ins that might be causing that error? I ran your code (from VBA) and it ran fine.
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.