No BSD License  

Highlights from
saveppt

4.67347

4.7 | 50 ratings Rate this file 109 Downloads (last 30 days) File Size: 3.92 KB File ID: #340

saveppt

by

 

06 Aug 1999 (Updated )

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

Editor's Notes:

This file was a File Exchange Pick of the Week

| Watch this File

File Information
Description

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.

Acknowledgements

This file inspired Save2word, Quick Figure, Office Doc Read/Write/Format Ms Office Docs (Xls/Doc/Ppt), Write To Word From Matlab, Matlab Controls And Writes Power Point, Paste A Matlab Figure To Excel, Subplot Ppt, Saveppt2, and Smart Power Point Exporter.

MATLAB release MATLAB 6.0 (R12)
Other requirements This routine was tested on Matlab R12, R13, and R14. Operating systems include Windows NT 4.0, Windows 2000, and Windows ME. PowerPoint versions include PowerPoint 97, 2000, 2003.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (71)
02 Jul 2014 Megna  
03 Jun 2014 Yellavenkatasunil Jonnalagadda

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?

22 Apr 2014 Ken

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

26 Mar 2014 Molly Rossow  
11 Feb 2014 Mark

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.

10 Feb 2014 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.

21 Jan 2014 Ken

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

Thanks,
Ken

15 Jan 2014 Amit Davidi  
02 Oct 2013 Silin

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?

Thanks,

SD

03 Sep 2013 JC M

Mark,
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>
Thanks,
JC

26 Aug 2013 Mark

JC,

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!

Mark

23 Aug 2013 JC M

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.

Thanks,
JC

15 Jul 2013 Mark

Ravi,

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!

Mark

12 Jul 2013 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

Ravi

12 Oct 2012 Suresh Deoda

Thanks, Its very useful!

14 May 2012 Don

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

12 Mar 2012 Scott

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

op=invoke(ppt.Presentations,'Add',0)

12 Mar 2012 Scott

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);

14 Feb 2012 S  
29 Jan 2012 Hugh

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

02 Nov 2011 Stanley Fletcher

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
set(pic1,'Width',single(slide_W))
if pic1.Height > slide_H*.8
set(pic1,'Height',single(slide_H*.8))
end

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.

28 Oct 2011 prashanth reddy

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

21 Jul 2010 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.

10 Mar 2010 Mark

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)
figure
x = -pi:pi/10:pi;
y = tan(sin(x)) - sin(tan(x));
plot(x,y,'--rs','LineWidth',2,...
'MarkerEdgeColor','k',...
'MarkerFaceColor','g',...
'MarkerSize',10)

% --- 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:
saveppt

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
else
print('-dmeta',prnopt)
end

07 Jan 2010 Glenn

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.

Thanks

20 Nov 2009 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

12 Aug 2009 Mel

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);
to
% 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');
to
% Insert the contents of the emf-file
pic1 = invoke(new_slide.Shapes,'AddPicture',emffile,true,true,0,0,...
slide_W,slide_H);
% Delete the temporary file
delete(emffile);

12 Aug 2009 Mel

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');
else
% Open existing presentation:
op = invoke(ppt.Presentations,'Open',filespec,[],[],0);
end

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

% Capture current figure/model into clipboard:
if nargin<3
print -dmeta
else
print('-dmeta',prnopt)
end

% 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)));
end

if ~exist(filespec,'file')
% Save file as new:
invoke(op,'SaveAs',filespec,1);
else
% Save existing file:
invoke(op,'Save');
end
[...]
Note that titletxt has to be cell array of strings now.

29 May 2009 Mel

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

20 May 2009 Jisang Park

super!

11 Jan 2008 R K

works great.

31 Oct 2007 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?

11 Jun 2007 Karthik K

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

04 Apr 2007 Dalal Helmi

This is a helpful addin file

01 Dec 2006 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

01 Dec 2006 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.

01 Dec 2006 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.

26 Oct 2006 Zach L

Ah, the command is:

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

24 Oct 2006 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:

ActiveWindow.Selection.SlideRange.Shapes.AddPicture(FileName:='filenam
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.

18 Aug 2006 Keith McCarron

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

27 Jul 2006 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
Loop
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.

25 Jul 2006 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.

template_file=fullfile(pwd,'my_template.pot');
invoke(op,'ApplyTemplate',template_file);

21 Jul 2006 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
set(new_slide.Shapes.Title.TextFrame.TextRange.Font,'Name','arial');
after line 89 where the text is inserted into the title object.

25 Apr 2006 Les Yeh  
02 Apr 2006 Peter NĂ©meth  
28 Mar 2006 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).

25 Oct 2005 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.

12 Oct 2005 Bernhard Knigge

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

29 Aug 2005 john doe

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

16 Feb 2005 Tycho Hoogland

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

04 Feb 2005 Krishna Pillai

smart :)

03 Dec 2004 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.

02 Dec 2004 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 :
set(0,'DefaultAxesFontName','arial')

02 Dec 2004 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?

30 Nov 2004 Erik Mattson  
26 Nov 2004 Konstantin Zhukov  
26 Nov 2004 Mr Cool

Nice work

25 Nov 2004 Oscar Herrera Agudelo

Excellent for all that we use this
Thankyou

24 Nov 2004 Edo Becker

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

24 Nov 2004 I. Kalatzis

!!

01 Nov 2004 CC Chang

amazing!

16 Apr 2004 Dave DeVilbiss

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

Otherwise, Excellent

12 Dec 2003 Lucas Goldstein

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

17 Jul 2003 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!

20 Jun 2003 Xavier Caldera  
16 Mar 2003 Lina Chang

Extremely handy when preparing Powerpoint presentations.

19 Feb 2003 Anna Sawabini

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

07 Jan 2003 Jack Zhu  
18 Jun 2002 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.

13 Jun 2002 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.

18 Apr 2002 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.

Updates

desc

30 Oct 2001

Updated to run with MATLAB 6.0

04 Oct 2005

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.

Contact us