programmatically creating powerpoint macro

A

Alex Bendig

Everyone,

I have a valid reference to a PowerPoint.Presentation object. I'd like to
programmatically create a macro and have that available during program
runtime.

As far as I can tell, this should do the trick:
VBIDE.VBComponent vbc;
vbc =
currentPresentation.VBProject.VBComponents.Add(VBIDE.vbext_ComponentType.vbe
xt_ct_StdModule);
string s = "sub vbaSwitchToMaster()\r\n"+
"currentPresentation.Windows.Item(1).ViewType =
PowerPoint.PpViewType.ppViewTitleMaster\r\n"+
"end sub";
vbc.CodeModule.AddFromString(s);

Unfortunately, it does not.

In fact, this test line fails already:
Console.WriteLine(currentPresentation.VBProject);

Instead, this exception is being thrown (unfortunately):
An unhandled exception of type 'System.Runtime.InteropServices.COMException'
occurred in WindowsApplication5.exe
Additional information: Exception from HRESULT: 0x80048240.

I am confused. Certainly, I would appreciate any sort of constructive
hint/suggestion/etc. which may shed some light on the matter.

Thanks in advance and best regards,

Alex Bendig
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top