MATLAB Answers

How can I create slides in MS Powerpoint 2007 using MATLAB 7.13 (R2011b)?

44 views (last 30 days)
I am using Windows 7 and MATLAB 7.13 (R2011b). I want to create a new presentation and add slides to it in MS Powerpoint 2007 using MATLAB and ACTXSERVER.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 9 Apr 2013
The Microsoft APIs for Office 2007 are different from those used for Office 2003. You can create a new presentation in Powerpoint 2007 and add slides to it using MATLAB with the following code (note the commented sections for modifying an existing presentation):
% Create an ActiveX object
ppt = actxserver('powerpoint.application');
ppt.Visible = 1;
% Open an existing presentation by supplying the fullpath to the file
% Create a new presentation
% Add a blank slide to the presentation
layout = ppt.ActivePresentation.SlideMaster.CustomLayouts.Item(1);
ppt.ActivePresentation.Slides.AddSlide(1, layout);
% Add a custom slide and add an image to that slide
layout = ppt.ActiveWindow.Selection.SlideRange(1).CustomLayout;
slides = ppt.ActivePresentation.Slides;
newSlide = slides.AddSlide(1,layout);
%Add the image using the fullpath of the image file
pic = ...
ppt.ActiveWindow.Selection.SlideRange(1).Shapes.AddPicture( ...
fullfile(matlabroot,'toolbox','images','imdemos','football.jpg'), ...
% To add another image
pic2 = ...
ppt.ActiveWindow.Selection.SlideRange(1).Shapes.AddPicture( ...
fullfile(matlabroot,'toolbox','images','imdemos','football.jpg'), ...
% If you opened an already existing presentation, save it using
% Else save a newly created presentation at a particular location
% Close Powerpoint and delete the object

More Answers (0)




Community Treasure Hunt

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

Start Hunting!