Do you have any other add-ins that might be causing that error? I ran your code (from VBA) and it ran fine.
Open a powerpoint presentation and hide the window
-
29-06-2022 - |
質問
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.
解決 2
他のヒント
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);
所属していません StackOverflow