0
votes

I am writing a WPF application in C# .Net 4, in which I am trying to open a PowerPoint application instance and then open a new presentation.

In general the code to do this looks like:

var myApp = new Microsoft.Office.Interop.PowerPoint.Application();
var myPres = myApp.NewPresentation(Microsoft.Office.Core.MsoTriState.msoTrue);

This works fine unless, as in my situation, Powerpoint loads vba AddIns when it opens, which take some time to load.

In this case, PowerPoint tries to open the new presentation, fails, and throws a COM Exception.

My current workaround is pretty horrible:

var myApp = new Microsoft.Office.Interop.PowerPoint.Application();
MessageBox.Show("Confirm that PPT has finished opening.");
var myPres = myApp.NewPresentation(Microsoft.Office.Core.MsoTriState.msoTrue);    

Does anyone know of a way to either: 1) test for Powerpoint having finished opening? or 2) stop addins loading when creating a new Powerpoint.Application?

Or any other solution of course!

I can't find anything to this end in the Microsoft documentation or on StackOverflow.

Many thank for any help, Tim J

1

1 Answers

0
votes

While you could theoretically stop add-ins from loading by removing the registry entries that control them, it's not a good idea.

But notice that when you start PPT manually, you get the splash screen while add-ins are loading (it even points the finger at especially slow ones), then finally the app UI appears. You might be able to put your code in a loop while waiting for the PPT window to appear, then proceed.

Or build in small delays, trap any errors that occur and try again.