3

I am trying to save selected slide so it doesnt retain my source template. how do i retain the existing template while i save the slides

   private void SaveSelectedSlide_Click(object sender, RibbonControlEventArgs e)
    {
        try
        {
            PowerPoint.Application ppApp = Globals.ThisAddIn.Application;
            PowerPoint.SlideRange ppslr = ppApp.ActiveWindow.Selection.SlideRange;
            string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            var temporaryPresentation = Globals.ThisAddIn.Application.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);
            Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout = ppApp.ActivePresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];

            for (int i = 1; i <= ppslr.Count; i++)
            {
                var sourceSlide = ppslr[i];
                sourceSlide.Copy();

                var design = sourceSlide.Design;
                temporaryPresentation.Slides.Paste();


            }

            temporaryPresentation.SaveAs("Temporary", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Microsoft.Office.Core.MsoTriState.msoTrue);

            temporaryPresentation.Close();

        }
        catch (COMException Ex)
        {
            Debug.WriteLine("Some problem" + Ex.Message + Ex.StackTrace);
            MessageBox.Show("PLease enter text ");
        }

    }
test
  • 114
  • 13
  • Is the presentation changed when you call the [SaveAs](https://msdn.microsoft.com/en-us/library/office/ff746389(v=office.15).aspx) method of the Presentation class? – Eugene Astafiev Feb 25 '15 at 13:58
  • This code works pretty fine when I tested it. What exactly is the problem here? – Pilgerstorfer Franz Feb 25 '15 at 15:00
  • when the slides get saved the blank template are used. if we use some template it wont select that template. it juzt copies all shapes to destination. without source template. – test Feb 25 '15 at 18:00
  • @PilgerstorferFranz did u find any solution to this.... – test Feb 26 '15 at 05:32
  • @EugeneAstafiev yes we are creating another temporary presentation and copying all the source file data to that temporary presentation – test Feb 26 '15 at 05:34
  • http://stackoverflow.com/questions/28673502/add-new-slide-command-that-exists-in-home-menu-and-add-it-in-addin-ribbon-in-c-s – test Feb 26 '15 at 05:40
  • also if u guys could help me out with this – test Feb 26 '15 at 05:41

1 Answers1

3

I think I got what you want. When pasting the new slide, save the new SlideRange. Afterwards assign the design of the source slide.

PowerPoint.Application ppApp = Globals.ThisAddIn.Application;
PowerPoint.SlideRange ppslr = ppApp.ActiveWindow.Selection.SlideRange;
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var temporaryPresentation = Globals.ThisAddIn.Application.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoTrue);
Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout = ppApp.ActivePresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];

for (int i = 1; i <= ppslr.Count; i++)
{
    var sourceSlide = ppslr[i];
    sourceSlide.Copy();

    var design = sourceSlide.Design;                    
    SlideRange sr = temporaryPresentation.Slides.Paste(); // get newly created slideRange
    sr.Design = sourceSlide.Design; // manually set design
}
temporaryPresentation.SaveAs("Temporary", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsPresentation, Microsoft.Office.Core.MsoTriState.msoTrue);
temporaryPresentation.Close();

It worked for me. Please let me know if this is the expected behaviour!

Pilgerstorfer Franz
  • 8,303
  • 3
  • 41
  • 54
  • this didnt work for me. all the shapes are saved but not their templates . also i have a nother doubt http://stackoverflow.com/questions/28935838/add-shape-from-a-ppt-slide-within-a-project-to-your-current-open-slide – test Mar 09 '15 at 05:44
  • could you please upload your ppt(x) file so I could make some test on the original file? – Pilgerstorfer Franz Mar 09 '15 at 07:23
  • use any public share platform or just send it to me by mail franz.pilgerstorfer@pundt.at – Pilgerstorfer Franz Mar 09 '15 at 07:48
  • no that we save this ppt. It gets save in document by default i want a dialog box where i can select location to save this. – test Mar 11 '15 at 12:15
  • also when i save slide the 1st slide ie slide nos 1 gets save at last and last slide gets saved 1st – test Mar 11 '15 at 12:19