add new slide to exisiting powerpoint in matlab

To add a new slide to an existing PowerPoint presentation in Matlab, you can use the following code snippet:

% Open PowerPoint presentation
ppt = actxserver('PowerPoint.Application');
pptFile = fullfile(pwd, 'example.pptx');
presentation = ppt.Presentations.Open(pptFile);

% Add a new slide
slideCount = presentation.Slides.Count;
presentation.Slides.Add(slideCount+1, 11); % 11 is the slide layout index

% Save and close the PowerPoint presentation
presentation.Save;
presentation.Close;
ppt.Quit;
392 chars
14 lines

In the above code, we first create an ActiveX server object to interact with PowerPoint. We then open the PowerPoint presentation file named example.pptx. To add a new slide, we get the count of existing slides using presentation.Slides.Count, and then use the Add method to create a new slide. The second argument to Add is the slide layout index, which in this example is set to 11 (a blank slide layout).

Note that you may need to adjust the slide layout index depending on the layout you want to use. The available layout indices can be obtained using presentation.Designs.Item(1).SlideMaster.CustomLayouts.Count. Finally, we save and close the PowerPoint presentation, and exit the ActiveX server object with ppt.Quit.

related categories

gistlibby LogSnag