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
%ppt.Presentations.Open('C:\MyFolder\test.ppt');
% Create a new presentation
ppt.Presentations.Add()
% 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'), ...
'msoFalse','msoTrue',100,20,500,500);
% To add another image
pic2 = ...
ppt.ActiveWindow.Selection.SlideRange(1).Shapes.AddPicture( ...
fullfile(matlabroot,'toolbox','images','imdemos','football.jpg'), ...
'msoFalse','msoTrue',200,220,500,500);
% If you opened an already existing presentation, save it using
%ppt.ActivePresentation.Save;
% Else save a newly created presentation at a particular location
ppt.ActivePresentation.SaveAs(fullfile(pwd,'test.ppt'));
% Close Powerpoint and delete the object
ppt.ActivePresentation.Close;
ppt.Quit;
ppt.delete;

More Answers (0)

Products


Release

R2011b

Community Treasure Hunt

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

Start Hunting!