File Exchange

image thumbnail


version (618 KB) by Jed F.
Save Matlab figure(s) to a PowerPoint Slide


Updated 03 Jun 2010

View Version History

View License

saveppt2 builds on saveppt to include many new options.

Saveppt2 Features:
Save multiple plots to the same PowerPoint slide.
Create slides with and without a title.
Add notes to a PowerPoint slide
Scale the figure to fill the slide (with and without locking aspect ratio).
Horizontally and vertically align figures on the slide.
Use a template file for creating a new presentation. (Useful for automated reports)
Add padding to any of the sides for use with scaling or aligning figures.

New in Jun 2010.
Can choose between Metafile or bitmap drivers when copy and pasting to PowerPoint.
Add a blank title page or blank page from Matlab.
Add comments & textbox to slide.
Make PowerPoint visible during operations. (Required for Comments).
If there is another PowerPoint presentation open, PowerPoint will not quit.
Disable closing of PowerPoint presentation and return ActiveX object for further programmatic slide manipulation.

Also added a method to do batch processing by keeping an ActiveX session open and just adding new slides to it.
for i=1:10

The zip file includes saveppt2 and a sample presentation created with saveppt2. The code for creating the presentation is also included.
GitHub Project:

Cite As

Jed F. (2021). saveppt2 (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (64)


Han Lin

For people looking for a more modern version of a programmatic PowerPoint exporting code that works well with MATLAB 2016+, check this out:

N Kando


Updated MS Office from 2010 to 2013.
Figure size is experiencing a gain somewhere during the export to .emf or .ppt. If figures are created with a specified print/paper size/position (say, 10" x 7.5"), they are now imported to .ppt as images which are larger than 10" x 7.5" slides. This was not a problem in the old version of MS PPT.

We tune and adapt as needed, but removing the factor offset would be better.

MS PPTs native format has been changed to .pptx. Could .pptx format compatibility be added?

Could relative path compatibility be added?

Relative path (desired):

Absolute path (currently required):

Could 1/0 be added as acceptable parameter value settings (in addition to to true/false, on/off, yes/no)?
I've seen the code, I understand that 1/0 is more difficult to implement, as I assume it would need to be converted to a true/false during processing.

Thanks for any support given : j

saeed ghaemian

Feixiao Long

Andre Marques


I found that replacing:



hgexport(addlParms.figure(i),'-clipboard' )

cleared the errors stated in my previous post.



I recently switched over to 2015a and despite the provided solutions, the error below still occurs:

Error using Interface.Microsoft_PowerPoint_14.0_Object_Library.Shapes/Paste
Invoke Error, Dispatch Exception:
Source: Microsoft PowerPoint 2010
Description: Shapes.Paste : Invalid request. Clipboard is empty or contains
data which may not be pasted here.
Help File:
Help Context ID: 0

What did MATLAB 2015a update to cause this error?

Gero Nootz

Works well after Curtis fix with Office 2010 and MatLab 14b.

Gero Nootz


In MATLAB2014b, I receive the following error:
Undefined function 'abs' for input arguments of type 'matlab.ui.Figure'.

Error in num2str (line 66)
xmax = double(max(abs(widthCopy(:))));

Error in saveppt2 (line 557)
print(addlParms.driver,['-f' num2str(addlParms.figure(i))],rendOpt,resOpt);

Error in DataAnalysis_d11_12_14 (line 59)
saveppt2('ppt', ppt_obj);

The error can be corrected by replacing:
print(addlParms.driver,['-f' num2str(addlParms.figure(i))],rendOpt,resOpt);



Is it possible to embed the .fig file onto the ppt slide?


Excellent script. Very useful.
For those that struggled with the template option, I found you had to specify the full path to the template file for it to work.

Eric Sampson

Hi all, for those of you who are encountering an error when using this function with PowerPoint 2013, to correct this issue you can replace the following line:
pic1 = invoke(new_slide.Shapes,'Paste');

with the following two lines:

picShapeRange = invoke(new_slide.Shapes,'Paste');
pic1 = invoke(picShapeRange,'Item',1);

This fix will still work when using older versions of PowerPoint.

Jed F.

My work machines are stuck at Office 2003 and I use OpenOffice on all my personal machines. I have no way to test this out with newer version of Office. Sorry.

I changed the Git projects to 1 project per repository:

If anyone would like to fork it and submit your changes.


Dale: Thank you for posting your work around. You saved me!

Jedediah: I love this script


This is great, thanks Jed. I have similar issue as Deng first noted below, seems to be related to Office 2013, because it did work with older version of Office.

A work around is to comment out the section which fits and scales the figure into the slide.

comment out from line approx 560 % Get height and width of picture: to the end of the for i=1:fig.count loop.


Sue Peters

I had a similar problem to Deng, and wondering if anyone has found a solution. Thanks

Sue Peters


This is great and I use saveppt old version in the past. One question: On different computer, it generates different slides. I forget where to change the setting to avoid that. Can anyone give me a hint?


I love this code, thank you! It's incredibly useful for automatically creating a PPT presentation from a large number of plots in my code.

But, I ran into a puzzling error where it refused to insert a figure into a PPT file, for a particular figure I created in GUIDE. It turned out the problem was the "num2str" call on line 557 was truncating digits in the figure handle value and the result was not a valid figure handle. I changed the code on line 557 to "num2str(addlParms.figure(i),'%.20f')" and now it seems to work!

Ankit Gupta

Is it possible to use this for multiple images already in a folder, or matlab array, or use it in a loop adding new image in new slide.


Is there a way to make this work on Mac? Thanks for your suggestions.

vic tsai



Hi Jedediah
Recently I use this file to export .fig to office 2013. I found an error like this :
Error using Interface.Microsoft_PowerPoint_15.0_Object_Library.ShapeRange/get
Error: Object returned error code: 0x800A01A8

Error in saveppt2 (line 561)
pic_H = get(pic1,'Height');
What should I do?

Thanks for your help

Linda Seltzer

Please disregard my previous question. I found the error in my script. I shouldn't be debugging and posting questions at 5 am, but alas it happens.

Linda Seltzer

I tried to run the example in the documentation:
happt = saveppt2('batch.ppt','init');
for i = 1:10

I am getting the following error message.
??? Error using ==> saveppt2 at 247
Failed invoking object. Verify that it is a PPT object as returned from a
saveppt2(file,'init') function.

Error in ==> testbatchppt at 6

We are using
MATLAB Version (R2011a)
Windows Vista Business Version 6.0

Thank you for any information / fixes.

Tai-Yen Chen

just wonder is there a way to change the title font size??

Tai-Yen Chen



Rohit Mundra

Works really well on XP however it crashes MATLAB on my Windows 7 system (tried both, batch mode and otherwise) - I suspect it has something to do with the ActiveX controls...


Excellent tool.. really helps me a lot.

Is there any way, we can make this tool through a compiled Matlab code?

Craig Remillard

@Manouch - I also get this error. It happens when I change the renderer from '' or 'painters' to 'opengl' or 'zbuffer':

It does not error out if I change -dmeta to -dbitmap in this line:

print('-dmeta',['-f' num2str(addlParms.figure(i))],rendOpt,resOpt);

BUT, then I have two other problems - first, the figures all become visible even though I have set them as not-visible (I assume there's a screen capture in bitmap print driver, because this happens when I just export figures to bitmap in Matlab as well). Second, all the bitmap figures in the PPT are solid black.

To summarize: the raster renderers crash out if I don't use -dbitmap, and they output black pictures and fill my screen if I don't. And the vector renderer (painters) doesn't crash with either option, but the vector images are insanely large for my dataset with -dmeta, and the raster images are still black blocks with -dbitmap. Can anyone offer a way to export raster images? I'll keep working on it and let y'all know if I figure it out.


Very useful already. Wonderful!

One revision suggestion. The chart in Matlab with date labels looking nice, but when exported to powerpoint, the date lables are crowded together. The resizing did not preserve the original look.

Monica Barbu-McInnis

Awesome tool! I have a question about the 'template' keyword. I am specifying a template when creating a new ppt file of two figures, but the figures end up placed on a new slide while the first slide with the actual ppt template is blank. Am I missing any additional keywords?

Carey Smith

Works nice & simple

Nando Trindade

Awesome script! Is there a way to put an option to add a border around the figure? We had a different script that didn't work too well, but it had a line ppt_pic=op.Application.Windows.Item(1).Selection.ShapeRange.Item(1);
ppt_pic.Line.Visible = -1; I'm not sure how to replace the ppt_pic to use your code to add this border.

Also, is there a way to place the title in the template title slot instead of a position above the figure? Thanks for sharing.

Jed F.

Other requirements: Requires Windows because it uses ActiveX. This was tested on 2007b and Office 2000 on Windows XP SP3. It should work with other releases.


Attempting to run the first example, I get 'Error opening PowerPoint'. I'm using a Mac (R2011a and MS Office for Mac 2011 - is it likely this is the problem?

Lan Du



Works great - very helpful tool!

Andrew Wind

Just found this function following the Pick of the Week review of 2004 picks. It appears to work great thus far for figures. Is there any way to capture a GUI though? I can't seem to point it to the GUI even if all my other figures are closed. I would love to capture my Input GUI with all the values and then the results figures all in one ppt.

Jed F.

Unfortunately my company is sticking with Office 2000 for the near future and I only run OS X/Linux at home.

I will try and get to a computer with the latest office and see if I can fix that.

Henik Vargas

Thank you for such an excellent and well coded function. Test automation in matlab would be incomplete without it. One minor question: Is it possible to save the file as pptx instead of ppt?

Jed F.

How are you calling the template? PowerPoint is complaining that it can't open the template file that you provide it.


I've used your script for several years now--it's great!

However, when trying to use the template argument, I get the following error:

322 op = invoke(ppt.Presentations,'Open',addlParms.template,[],[],0);
??? Invoke Error, Dispatch Exception:
Source: Microsoft Office PowerPoint 2007
Description: PowerPoint could not open the file.
Help File:
Help Context ID: 0

This has been a problem for both the v1 and v2 scripts. Any advice would be appreciated!

Jed F.

I'm only on Windows XP with Office 2000 and get no problems with surf or plot3 So it sounds like something with your setup.

Have you tried using the bitmap driver?


Unfortunately it doesn't work for me. But I think, it is my lack of knowledge about Matlab...
I tried to save a 3d-figure created with surf in a powerpoint file with saveppt2 an got the following message:

??? Invoke Error, Dispatch Exception:
Source: Microsoft Office PowerPoint 2007
Description: Shapes.Paste : Invalid request. Clipboard is empty or contains data which may not be pasted here.
Help File:
Help Context ID: 0

Error in ==> saveppt2 at 559
pic1 = invoke(new_slide.Shapes,'Paste');

I would appreciate, if anyone could tell me, what was my mistake.

Thanks in advance!


Precious time saver!


Thanks for the great tool! I added the following code that lets you add text to a slide. (Not showing the argument parsing part) Someone with more experience with this can surely improve it.

% Add textbox if they are specified
if isfield(addlParms,'textbox')

% Convert \n and \t into characters for powerpoint

% Set layout of slide

% Set some handles
% I'm not sure what's different between TextFrame1 and TextFrame2
% But, the AutoSize property isn't available on TF1 (and it doesn't
% seem to matter if I add the actual text to TF1 or TF2.
tf1 = new_slide.Shapes.Placeholders(1).Item(2).TextFrame;
tf2 = new_slide.Shapes.Placeholders(1).Item(2).TextFrame2;

% Turn off bullets

% Set text contents and font
tf2.TextRange.Font.Name = 'Courier New';

% Format paragraph, remove spaces between lines
pf = tf2.TextRange.ParagraphFormat;
set( pf, 'SpaceBefore', 0.2, ...
'SpaceWithin', 1, ...
'SpaceAfter', 0);

% Format shape so the text will be shrunken to fit in box

% Finally, add the text
tf2.TextRange.Text = addlParms.textbox;

% I have no idea why I have to do this, if I don't the
% text does not resize.
%fprintf('Autosize property is: %s\n', get(tf2, 'AutoSize'));


Great great Tool,

have been using your ver. 1 for some time and just switched over to ver. 2. Short question though, do you have a script to easily export tables (or present matrices/cell arrays) from Matlab to ppt? I have been looking for a script for some time, but cannot find a really useful one...



To avoid losing unsaved ppts, comment out this line:


(line 420 in 25 Mar 2008 version)

If you don't have any open ppt's, powerpoint will still close normally

[Tested using powerpoint ver 2007]


Dan Selters

Jaroslaw Tuszynski

great improvement over saveppt . Thanks


Works great.
One suggestion: you use
to keep a figure's size unchanged,
print('-dbitmap',['-f' ...
should be used.
Perhaps add this as an extra option?

Ameya Deoras

Saved me some time. Works with R2009a

Wolfgang Schwanghart

Great function. The only minus is, that it automatically shuts down powerpoint and there is no warning. So unsaved ppts will be lost.

Vincent Bonin

c garven


Nathan Brahms

Very nice! This will make my life easier...

James Cai


D Selters


MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!