Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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!

share|improve this question
    
Have you tried using PPspliT_main instead of pres1.ppt'!PPspliT_main as the last parameter? Including pres1.ppt tells PowerPiont 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. –  Steve Rindsberg Apr 6 '12 at 14:56
    
@SteveRindsberg Aha, that got it! Now that you point it out, that makes perfect sense (and in hindsight, is painfully obvious). In my actual code, I had the filename being drawn from a variable, instead of just hard-coding pres1.ppt. But I wasn't aware that the filename wasn't required in there. Thanks so much for your help. Would you mind reposting your comment in an answer so that I can resolve it and upvote it? (I'm assuming that even though I'm new to StackOverflow, I can upvote others' answers to my own questions?) –  Aaron Apr 6 '12 at 20:47
    
Glad it helped. I've reposted it as an answer (was hesitant to do that becuase I wasn't entirely certain it would work ... only 95% <g>) –  Steve Rindsberg Apr 7 '12 at 17:43
add comment

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.