Can I add a PNG file to an existing PowerPoinit presentation using MATLAB?

2 views (last 30 days)
Brad on 12 Feb 2017
I'm attempting to add a PNG file to slide 2 of an an existing 2-slide PowerPoint presentation using the following code;
% Clear out all workspace variables, close all open figures, and clear the
% command window
clear all;
close all;
% Create Common Object Model (COM) server so MATLAB can export data to
% PowerPoint
g = actxserver('powerpoint.application');
% Open PowerPoint and make it visible
g.Visible = 1;
Presentation = g.Presentation;
% Prompt the user for the PowerPoint file to open
[fn, pn] = uigetfile('*.ppt', 'Select PowerPoint File To Amend');
filename = fullfile(pn, fn);
Presentation = invoke(Presentation, 'open', filename);
% Get current number of slides
slide_count = get(Presentation.Slides, 'Count');
% Add Dice PNG to slide 2 in the existing Test slides file
slide_count = int32(double(slide_count));
PNG_To_Slide = invoke(Presentation.Slides, 'Add', slide_count, 1);
Image1 = PNG_To_Slide.Shapes.AddPicture('C:\Documents and Settings\My Documents\MATLAB\PNG_Dice.png', 'msoFalse', 'msoTrue', 0,75,620,440);
% Save PowerPoint presentation
Presentation.SaveAs('C:\Documents and Settings\My Documents\MATLAB\New_Slides.ppt');
% Close PowerPoint as a COM automation server
While this does place the PNG file in the existing PowerPoint slides, I've had to add another slide just to do it. The result is a 3-slide PowerPoint file with the dice PNG on slide 2 of 3 - instead of slide 2 of 2.
Is it possible to add a PNG to an existing PowerPoint presentation without having to add a separate slide?

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!