Click here to Skip to main content
14,331,160 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi
For an application that I am working, I need to insert slides from one pptx into another.

I tried doing this using the following code

mi_App = new Microsoft.Office.Interop.PowerPoint.Application();
mi_Pres = mi_App.Presentations.Open2007("File1.pptx", MsoTriState.msoTrue,MsoTriState.msoTrue, MsoTriState.msoFalse, MsoTriState.msoFalse);

mi_Pres.Slides.InsertFromFile("File2.pptx", 2, 1, 2);

mi_Pres.SaveAs("File3.pptx", PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoFalse);
mi_Pres.Close();


This does insert the corresponding slides from File2.pptx. But the problem is that their background is lost. The slides take up the default background of File1.pptx.
The slides in File2.pptx have the backgrounds defined for each slide. But the ones inserted into the new pptx have a uniform background that is same as the default background of File1.pptx.

I tried copying background by assigning to mi_Pres.Slides[3].Background

But that did not work, because Background is a readonly!

Can you please tell me what is the correct way of doing this? How do I insert slides from another file, along with the corresponding background?
Posted
Comments
Manfred Rudolf Bihy 31-Jul-11 10:30am
   
Interesting question. 5+
I haven't tried something like that before so I can't really help you. :(
Rate this:
Please Sign up or sign in to vote.

Solution 1

I don't use PowerPoint for anything, but I suspect the backgroun doesn't come over because it's parts of the slide template, not the slide itself. I have no idea what the workaround is.
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

Found the answer. Adding it here to complete this thread... Just had to add these lines...

mi_Pres1.Slides[3].FollowMasterBackground = MsoTriState.msoFalse;
mi_Pres1.Slides[4].FollowMasterBackground = MsoTriState.msoFalse;


FollowMasterBackground is true by default. If you explicitly set it to false, the inserted slides retain their own background.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100