none
How to generate a new Powerpoint slide? RRS feed

  • Question

  • Hi,

        I have been using following code to generate ppt on button click. Usually I will create the first slide as blank slide and duplicate it to no of slides I need to generate. Now I want to apply theme to my ppt. I went ahead and applied theme to the first slide.

                PowerPoint.Application ppt_application = new PowerPoint.Application();
                PowerPoint.Presentation ppt_presentation = ppt_application.Presentations.Add(MsoTriState.msoTrue);
                PowerPoint.CustomLayout ppt_layout =                         ppt_presentation.SlideMaster.CustomLayouts[PowerPoint.PpSlideLayout.ppLayoutTitle];

                ppt_presentation.PageSetup.SlideWidth = 720;
                ppt_presentation.PageSetup.SlideHeight = 540;
                PowerPoint.Slide slide;
                PowerPoint.TextRange text;
                PowerPoint.Shape shape;

                slide = ppt_presentation.Slides.AddSlide(1, ppt_layout);
                slide.Shapes[1].Delete();
                slide.Shapes.Placeholders[1].Delete();
                slide.ApplyTheme(@"C:\Users\Karthik\Desktop\custom.thmx");

    The theme has the first slide with a line, image at center and logo at bottom left. The rest of the slides don't have the image at center but has the line and logo.

    Since I duplicate the first slide, the theme of first slide applies to the rest of the slides( the image at center applies to the rest of the slides as well)

     The scenario is the same even if  I try to apply theme to the first slide or the ppt_presentation object.

    Please help me to generate new slide instead of duplicating the first slide.

    Saturday, August 22, 2015 7:43 AM

All replies

  • Hi Karthik,

    >> Please help me to generate new slide instead of duplicating the first slide.

    I made a test with your code in the PowerPoint add-in, and it will create a new PowerPoint file with an empty slide, I am not sure what do you mean by it duplicate the first slide.

    In my option, when you add a new slide, the PowerPoint will create a new slide according the SlideMaster page instead of the first slide. I think you could modify the first slide, and then add a new slide with your code to check whether it is the same with the first slide.

    For your requirement, I suggest you check the slide master (View->Master Views). If you want to create an empty slide, you could try the code below:

            private void NewSlide_Click(object sender, RibbonControlEventArgs e)
            {
                PowerPoint.CustomLayout ppt_layout = Globals.ThisAddIn.Application.ActivePresentation.SlideMaster.CustomLayouts[PowerPoint.PpSlideLayout.ppLayoutBlank];
                PowerPoint.Slide slide;
                slide=Globals.ThisAddIn.Application.ActivePresentation.Slides.AddSlide(1, ppt_layout);
                slide.Shapes[1].Delete();
                slide.Shapes.Placeholders[1].Delete();
                //slide.ApplyTheme(@"C:\Users\Karthik\Desktop\custom.thmx");
            }

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, August 24, 2015 6:30 AM
  • Hi Edward,

                    My ppt generation involves more than one slide(20 or more). So I have been using the above code to insert a new blank slide using

    slide=ppt_presentation.Slides.AddSlide(1,ppt_layout); ///New slide

    After a new blank slide is generated instead of using the above code I use

    slide.Duplicate(); ///Duplicate slide

    The slide master is defined to have first slide with image at center and two lines at bottom. And it also defines that the rest of the slides will have small image at bottom left and a line at the top of the slide. So the first slide have one design and rest of the slides have another design.

    Now each time I use ///New slide code first slide design is applied. And when I use ///Duplicate slide code the first slide design is duplicated.

    So the above two codes gives me same design/theme to all the slides of my presentation.

    Hope this clears you the question I had asked.

    Saturday, August 29, 2015 4:34 PM
  • Hi Karthik,

    >> Now each time I use ///New slide code first slide design is applied. And when I use ///Duplicate slide code the first slide design is duplicated.

    To be honesty, I am not sure your current situation. Whether did the code not work for generate new slide or duplicate slide? Based on your description, it seems that you could insert a new blank slide. It would be helpful if you could share us steps to reproduce your issue and screen shot about the result you got and the right result you want.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, August 31, 2015 7:49 AM
  • Hi,

    To my understanding, you would like insert image and apply theme to the first slide (master slide), then the image and theme will be automatically added to the rest slides and newly generated slide? If so, please check this solution: How to Add an Image to Slide Master in C#

    Hope it helps.

    Monday, November 16, 2015 8:21 AM