Click here to Skip to main content
15,881,413 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
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

C#
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
Updated 1-Nov-19 10:05am
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. :(

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.
 
Share this answer
 
Found the answer. Adding it here to complete this thread... Just had to add these lines...

C#
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.
 
Share this answer
 
v2
C#
PPT.Application app = new PPT.Application();
app.CommandBars.ExecuteMso("PasteSourceFormatting");
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900