I am designing a C# application that will open a PowerPoint presentation, split the slides with animations into separate slides, and then export the whole presentation to a series of JPG images. I'm working in Visual Studio 2010, with Microsoft Office 2010.
The project is centered around PPspliT, a VBA macro and add-in that another developer graciously provided, and it works very well! (Thank you!) In essence, I am looking to automate this add-in using an external C# application (as opposed to another macro or Office add-in). My current code is based on a helpful example from Microsoft. If the PowerPoint file to be converted contains the PPspliT_main
macro, the RunMacro
function in the example works just fine when used like this:
RunMacro(oPP, new Object[]{"'pres1.ppt'!PPspliT_main"});
However, if the macro is not saved in the PowerPoint file itself, the RunMacro
function's code throws a TargetInvocationException
because the macro does not exist (even though the add-in is installed). I want to be able to utilize the functionality of the add-in, so that any PowerPoint file can be operated on, not just ones that have the macro saved in them. I would imagine there is a simple way to accomplish this.
A function similar to Application.CommandBars.ExecuteMso("Copy")
seems like it is just what I need, but from what I've read, it sounds like only built-in functions have an idMso, but not custom functions (like this one). Is this true? Or perhaps I'll need to edit the PPspliT macro code itself to "expose" it in order to call it from my C# application?
I've done a fair amount of searching around for solutions, and have found many articles/posts that are similar to what I'm looking for, but they all seem different enough that they won't work for my situation. I'm new to working with macros/add-ins, so my terminology/understanding could very well be a bit off as well.
Any guidance would be appreciated. Thanks in advance for your help!
You'll want to use PPspliT_main
instead of pres1.ppt'!PPspliT_main
as the last parameter.
Including pres1.ppt
tells PowerPoint to look for the macro in that file specifically, whereas asking for just the macro name should allow you to call any Public sub or function defined in a loaded add-in.