File Exchange

image thumbnail


version 2.2 (3.92 KB) by

This function saves Matlab figure windows or Simulink models to a Powerpoint file.



View License

Editor's Note: This file was a File Exchange Pick of the Week

This function saves Matlab figure windows or Simulink models to a Powerpoint file in metafile format using the ActiveX interface. The figure or model is first copied to the Windows clipboard, Powerpoint is started, a new blank slide is added, the figure/model is pasted, the file is saved, and Powerpoint is closed. If the Powerpoint file does not exist, a new one is created. An optional input argument allows you to add a unique title to the PowerPoint slide when it is created. This routine is handy when a large number of graphics must be inserted into Powerpoint, such as within a FOR loop. It is also a good example of how to use ActiveX to move Matlab graphics to other Windows programs.
Version 2.2 allows figures to be saved quietly in the background without PPT being visible.

Comments and Ratings (76)

Feng Du

The said problem is how to add the pictures on the existing slide page rather than adding a new page.

Feng Du

Dear All,
The mentioned problem had been sovled by calling the method of "Range" instead of "Add".


Bruce (view profile)

I've got the same problem as Brian. I've been using this routine for years but now with Office365 it randomly does not close the powerpoint application and matlab hangs. If I end the powerpoint process in task manager my script takes off and continues. Any ideas on how to fix this?

I think this may not work with Office 365. Has anyone looked into this? Office365 was forced upon me and I will miss saveppt enormously.


Saagar (view profile)

Is there a way to embed the .fig file onto the slide as well?

Megna Hari

Hi Mark, This looks like a very good submission. I am a bit concerned about using it for my work because of no BSD license. Could you please clarify the license for this submission?


Ken (view profile)

Eric, thank you so much for this fix. This is going to be a big help to me and my lab group. Appreciate it!

Molly Rossow

Mark Brown

Mark Brown (view profile)

Thanks Eric. I still have Office 2007, although my company has said that Office 2010 will be deployed soon. No hope for 2013. I will try your fix on my archaic version of PowerPoint.

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.


Ken (view profile)

I'm having the exact same issue as JC and Silin after moving to Powerpoint 2013. Has anyone found a workaround for this?


Amit Davidi


Silin (view profile)

Hi Mark,

I have the same issue as JC does. Code:
pic_H = get(pic1,'Height');
fails and also I have Powerpoint 2013 installed. Have you by any chance know a workaround to make it compatible with microsoft office 2013?




JC M (view profile)

Thanks for the suggestion. I added the pause right after the paste but that did not solve the issue (even with a 5s pause).
I am calling saveppt in a loop, but the failure occurs the very first time, right after the first image is pasted into the first slide. it is not being centered, and the file is not saved.
In the debugger, the pic1 object is set to:
<1x1 Interface.Microsoft_PowerPoint_14.0_Object_Library.ShapeRange>

Mark Brown

Mark Brown (view profile)


Sorry to hear about the issue. I don't yet have PowerPoint 2013, so I can't be sure what is going on. I Googled the error code, and it may be related to an invalid object (pic1). If you are calling savePPT in a loop, PowerPoint may not be able to keep up and might be falling behind. Try putting a >> pause(0.5) statement after the call to savePPT. A second idea is to run the debugger and inspect the "pic1" object to see if it is valid. If I can find a copy of PPT 2013, I'll try to do some more debugging. Good luck!



JC M (view profile)

Great function that has been very useful over the years. but just was migrated to Powerpoint 2013.
I'm getting the following error:
Error using Interface.Microsoft_PowerPoint_14.0_Object_Library.ShapeRange/get
Error: Object returned error code: 0x800A01A8

Error in run_report>saveppt (line 522)
pic_H = get(pic1,'Height');

a similar error occurs with the next statement:
set(pic1,'Left',single((double(slide_W) - double(pic_W))/2));

Any suggestion would be greatly appreciated.


Mark Brown

Mark Brown (view profile)


SavePPT works by copying the figure to the Windows Clipboard, and only BMP and META formats are supported. (>> doc print). You might try one of the other submissions that were inspired by SavePPT. For TIFF, they will have to create a .TIFF file and read it into Powerpoint. I don't know if any of them do that. Good luck!


Ravi Rastogi

Just wondering, if there is a way to use your code to save *.tif images on the powerpoint slides.

I tried using, print('-dtiff',prnopt), but i kept getting this error

Warning: Files produced by the 'tiff' driver cannot be sent to printer.
File saved to disk under name 'figure1.tif'.
> In graphics\private\name at 74
  In print at 209
  In saveppt at 69
  In getOutputPresentation>getclinicalplots at 1817
  In getOutputPresentation at 1018

Please let me know if you have any suggestions or advice. Thanks


Suresh Deoda

Thanks, Its very useful!


Don (view profile)

Yes, This is a very useful program. I have used it to gather up many figures into an organized presentation.

I find that now that I have a presentation and want to add more figures to existing slides in this presentation. So what should I change in saveppt so that instead of invoking new slides it steps through the existing slides (starting at the slide I designate)and pastes figures onto these slides. (I can position and size the figures so that they would not step on the figures already on these slides.) Thanks


Scott (view profile)

Found a work around to ppt.Visible=0 not working.



Scott (view profile)

As of PPT 2010, you can no longer hide the application (ppt.Visible=0). You can only minimize it (ppt.WindowState = 2). However, you can still open a presentation hidden using
op = invoke(ppt.Presentations,'Open',filespec,[],[],0);


S (view profile)


Hugh (view profile)

Great. How do I copy the figures over as enhanced metafiles (so the image is exactly preserved)? Thanks.

For my application I needed to resize the image to fit the ppt slide automatically. It was simple enough and I thought I'd share how it's done in case anyone else is looking to do the same. I found inserting:

% Size Picture to fit slide
if pic1.Height > slide_H*.8

above the code block:

% Get height and width of picture:
pic_H = get(pic1,'Height');
pic_W = get(pic1,'Width');

did the trick for me.

I have standard company design template that I want to incorporate when ppt is started. Any quick ideas how to do that ?

Jeffrey Roth

Regarding an equivalent routine that will run on Matlab in linux and export the figures to a non-MS PowerPoint equivalent (i.e., OpenOffice), I have not seen anyone achieve this as of yet.

Since Linux does not use ActiveX it would have to use some different protocal to get the figures graphics into OpenOffice.

I am interested in this, and would welcome any progress people make on it. I imagine by learning more about OO and the Linux clipboard, it could be done.

We are leaning towards an alternative approach of using Matlab to
instead generate a LaTeX output directly, using .EPS figures
generated in Matlab. This involves straightforward ASCII text
generation (like fprintf commands). LaTeX also does have a PPT analog, in Slitex, which has now been superceded by the "slides" document class in LaTeX2e. One could port the graphics into a PPT-style document. Albeit, it is not exactly PPT but would look similar.

At this point, we have some scripts to produce LaTeX-generated, report-style documents with Matlab figures embedded in them. This is all done automatically so that the .tex code is generated at the same time as the .eps figure files. The .tex file can also be compiled by Matlab to produce a finished PDF with the figure
graphics embedded.

It seems like it would be a fairly straightforward extension to take
this existing code and use it to port the Matlab graphics into a
Latex-based briefing chart style (slides document class).

If people want more info on this, please let me know.

I don't think that the LaTeX "slides" documentclass is as fancy as PPT/OOin terms of ability to do animations, etc. But if you mainly want Matlab to produce a document that consolidates a large number of figure graphics into one file (for ease of viewing and data analysis), then it might satisfy these needs on a Linux platform.


Mark (view profile)

Here is a quick example of how I use pushbutton 1 to generate the plot and using the saveppt in pushbutton 2.

% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Establish valid file name:

I just can't see how the code below would capture the current figure. Need some help to allow me to embed this into my GUI.

% Capture current figure/model into clipboard:
if nargin<3
  print -dmeta


Glenn (view profile)

This is extremely useful.

Does anyone know a good resource for listing ActiveX objects? I'd like to also be able to add slides with text boxes in the body.


Jeffrey Roth

Do the authors or others know if there is an equivalent routine that will run on Matlab in linux and export the figures to a non-MS PowerPoint equivalent (eg, OpenOffice or StarOffice).
Thanks! Jeff


Mel (view profile)

I don't know if it is a bug (can't find it in the database) but it seems that when copying through the clipboard using the .emf option, dashed lines in the figures get converted into normal. This is irritating!

Everything works fine however if you do it by saving first the figure into an .emf file and then use Insert Picture->From File in PowerPoint to import the figure.

This can be done automatically by modyfing saveppt.m to save the figure into a temporary emf-file instead of the Clipboard.
1.Change the lines
   % Capture current figure/model into clipboard:
    print('-dmeta', prnopt);
 % Save current figure/model into a temporary emf-file
    emffile = fullfile(fpath, 'resfig.emf');
    print('-dmeta', prnopt, emffile);
2. Change
   % Paste the contents of the Clipboard:
    pic1 = invoke(new_slide.Shapes,'Paste');
 % Insert the contents of the emf-file
    pic1 = invoke(new_slide.Shapes,'AddPicture',emffile,true,true,0,0,...
    % Delete the temporary file


Mel (view profile)

A correction:). Adding ppt.delete does not solve the problem of the activeX server running ahead on itself as I claimed in my last comment:).

There is though a simple solution which also makes export of many figures much faster. Just give an array of figure handles as an additional argument to the function and move the loop over the figures into the application. Something like

function savepptmany(filespec, figvec, titletext, prnopt)
% Start an ActiveX session with PowerPoint:
ppt = actxserver('PowerPoint.Application');

if ~exist(filespec,'file');
  % Create new presentation:
  op = invoke(ppt.Presentations,'Add');
  % Open existing presentation:
  op = invoke(ppt.Presentations,'Open',filespec,[],[],0);

% Loop over figures
for addfig = 1:length(figvec)

  % Capture current figure/model into clipboard:
  if nargin<3
    print -dmeta

 % Get current number of slides:
 slide_count = get(op.Slides,'Count');
 % Add a new slide (with title object):
  slide_count = int32(double(slide_count)+1);
  new_slide = invoke(op.Slides,'Add',slide_count,11);

  % Center picture on page (below title area):
  set(pic1,'Left',single((double(slide_W) - double(pic_W))/2));
  set(pic1,'Top',single(double(slide_H) - double(pic_H)));

if ~exist(filespec,'file')
  % Save file as new:
  % Save existing file:
Note that titletxt has to be cell array of strings now.


Mel (view profile)

I am not en expert in ActiveX but adding
in the end of saveppt.m seems to solve the problem of running ahead of itself when saving many images. Excellent application!

Jisang Park



works great.

Thierry Dalon

On my PC the centered height position does not look fine.
By changing line 100 to
set(pic1,'Top',single((double(slide_H) - double(pic_H))/2));
it looks than centered to me.
Maybe it is a small bug?

Karthik K

amazing work.
I was just wondering if it is possible to export more than one matlab figure to the same slide ?

Dalal Helmi

This is a helpful addin file

Tim Yoder

The fix for the 64 bit computer is to change the flag on the print command from print -dmeta to print -dbitmap when capturing the current figure/model into clipboard

Tim Yoder

FYI, Line plots and images work on a 32 bit computer; images do not work on a 64 bit computer. Both computers used Matlab 2006b, Windows XP, and PowerPoint 2003.

Tim Yoder

First, this is an extremely useful function! But.... The function works great for line plots (i.e. Matlab figures from plot), but if I try to save images (i.e. Matlab figures from imagesc) the data area is black. Has any one else experienced this effect and is there a fix for the problem? I'm using Matlab 2006b on a 64 bit computer with Windows XP.

Zach L

Ah, the command is:

pic2 = invoke(new_slide.Shapes,'AddPicture',pic_path,0,1,imgleft,imgtop,imgwidth,imgheight);

Zach Lewis

I'm interested in slightly altering this function to include the option of inserting a jpeg instead of using the copy
paste method with vector graphics. I find that in doing this
manually I get a much cleaner image and the result is much less
dependant on the users screen resolution.
The problem however is that I'm not familiar with COM/ActiveX objects
and I'm not sure how to do this, or where to find a good resource for
info on implementing this.
Currently, I can run a VB script directly in powerpoint with the
following command:
e', LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:='XX',
Top:='XX', Width:='XX', Height:='XX').Select
where 'filename' is a file I can point to with matlab, and the 'XX'
is a number I can define. Any help would be greatly appreciated.

Keith McCarron

Probably one of the most helpful files I've downloaded from this site. Very easy to use as well.

Daniel Helmick

Very useful file. I had the same problem with my figures covering my titles. I wrote the following macro that can be used in Powerpoint to fix the problem:

Sub BringTitleToFront()

    ActiveWindow.View.GotoSlide 1
    counter = 0
    Do While counter < ActivePresentation.Slides.Count
        ActiveWindow.Selection.SlideRange.Shapes.Title.ZOrder msoBringToFront
        counter = counter + 1
        ActiveWindow.View.GotoSlide Index:=counter
    ActiveWindow.Selection.SlideRange.Shapes.Title.ZOrder msoBringToFront

    ActiveWindow.View.GotoSlide 1
End Sub

Open your presentation. Press Alt-F11. Insert a Module. Copy and paste the above code. Then run the macro.

Another useful resource when you start modifying the file more heavily is to read the mxdom2ppt.m file associated with the 'publish' command.

Jeffrey Roth

Alternatively, you can also specify a template file to use. The template should be in the local working directory. I put this in saveppt.m right after the powerpoint file is created/opened. See code below.


Jeffrey Roth

I couldn't get the font modification suggested by Bill Solomon below (2004-12-02) to work. I discovered that if you want to modify the font directly in the "saveppt.m" script, add
after line 89 where the text is inserted into the title object.

Les Yeh

Peter Németh

Alex Knight

A very handy tool and a good example of how to use MATLAB to control PowerPoint. One question, though: does anyone know how to adapt this to do "Paste Special" as I find my plots work better as enhanced metafiles (otherwise the aspect ratio is wrong).

Noah Siegel

This is a really handy script. If you don't want to have powerpoint. If you don't want powerpoint to actually open (become visible), you can make the following changes:

comment out "ppt.Visible = 1"
change op = invoke(ppt.Presentations,'Open',filespec);
to op = invoke(ppt.Presentations,'Open',filespec,[],[],0);

This will make powerpoint hide the presentation when opened, and as such not require the program window to be visible.

Bernhard Knigge

Great Job ! Would be nice if you could also change the position within ppt...

john doe

Nice. Very Nice. Takes the drudgery out of adding a lot of .fig files to Power Point. Thanks!

Tycho Hoogland

Fantastic time saver. Please read David Abraham's comments for fixing Office 2002/2003 compatibility.

Krishna Pillai

smart :)

Andrea Mari

Sorry: in my environment PowerPoints has Adobe Acrobat tool to save files in pdf. This puts the Adobe logo on the clipboard when PPT is started, and the Matlab figure goes lost. I understand it's very difficult to deal with everybody's environment... Thank you, anyway.

Bill Solomon

Fonts problem can be fixed by explicitly specifying the font in the matlab script (otherwise powerpoint just assigns a default font). Put this in your plot script :

Wolfgang Schwahn

Very useful and time-saving! My problem: The font will be changed - In the MATLAB-figure I have Arial font, but in the ppt I see a Times New Roman font. Why?

Erik Mattson

Konstantin Zhukov

Mr Cool

Nice work

Oscar Herrera Agudelo

Excellent for all that we use this

Edo Becker

exactly what you need, if you have to share a lot of figures to non-matlab users

I. Kalatzis


CC Chang


Dave DeVilbiss

Cool ... Thanks so much. One problem I am having is that the figure overwrites the title.

Otherwise, Excellent

Lucas Goldstein

Easy to use and a real time saver.
Good job!

David Abraham

I find this to be a very useful tool! I did discover a small problem upon upgrading to Office 2002- in this case, Powerpoint must be open before the copy-to-clipboard command is issued. Simply reverse those lines of code in the macro to get it working. This is because the Office clipboard is different from the system, and only is synchronized if PPT is running at the time of the paste!

Xavier Caldera

Lina Chang

Extremely handy when preparing Powerpoint presentations.

Anna Sawabini

Very useful! Should be incorporated as a standard part of Matlab.

Jack Zhu

Suresh Joel

Very useful!
For Matlab 5.3 (R11) the ppt actxserver has to be made visible (ppt.Visible=1; in the saveppt function) only when the file is opened and not when a new file is created. The size of the pasted picture also need to be made small.

Matt Remigy

Very useful function, specially when there are many plots to export to ppt using a loop. If the loop hangs after the first plot, just add a pause() after the saveppt() call to let the activex server close properly after each graph insertion.

Katie Image

Excellent. Saves me soooo much time!
I find it needs a pause(0.01) or something after it saves each sheet though, coz otherwise it runs ahead of itself and crashes.



Included BSD license.

Version 2.1 fixes a problem for users with Adobe PDF installed that caused an icon to appear in place of the desired figure window.

Updated to run with MATLAB 6.0


MATLAB Release
MATLAB 6.0 (R12)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video