File Exchange

image thumbnail


version (2.99 KB) by Suresh Joel
Paste figure to Microsoft word automatically using ActiveX.


Updated 31 Mar 2016

View License

Editor's Note: This file was selected as MATLAB Central Pick of the Week

A simple function to copy figure from MATLAB into MS Word automatically. It is a modification of saveppt (a function in File exchange) that save figures to MS Powerpoint.

Cite As

Suresh Joel (2021). save2word (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (48)

Sighart Schaufler

changes for DOCX

if ~exist(filespec,'file')
% Save file as new:
invoke(op,'SaveAs2',filespec,16); % 16 for Word default document file format. For Word, this is the DOCX format.

Anthony Corr

Resul Al

ashwini chavan

Hello, I am new to matlab can anyone tell me how to implement this code?


Zhengfan Liu

Patryk Dudek

Hey dear Programmers,
When using the function, is it possible to somehow creating a new file in the format '*.docx' because in the funtion it is only given as '.doic' and when trying to creating a new file it runs in an error.

Hevi Pavi

Francesco Botticella



Wow this is amazing and it saves a lot of time

Yonggang Zhu

Ursula Dora

Florian Kraus

Hi guys,

i got also the Problem.

"Invoke Error, Dispatch Exception: Source: Microsoft Word Description: Befehl misslungen Help File: wdmain11.chm Help Context ID: 9066"

In my Situation was the Problem the following.
I had a testbench, where all files ( over 1000) needs to get translate into English from German Version.

If i run my code, which was normally german and everything worked, i now got the Problem, when a plot was fixed to a word and the Picture in word was at the point to get labeled ("Abbildung").

The interessenting thing is, when i debugged the Code, the error did not occur or just in some cases.

So the reason was, that the word document Begins with german speech, but at the Point where the error occured i saw that the Document jumps to english speech.

When i clicked away the button "automatical speech detection" the error did not occur since yet.

Maybe that could help you, for me it took more then 1 week to detect this error.

Best regards

Jagan Mohan

Any onr could you please help me to convert MATLAB output in text to a word document automatically

mandava suryakala

If the figure files already to replace and paste at the same place in word document.
When running a save2word program multiple times for the same figures it keeps on adding the same to .doc


how can we edit a image in MATlab which is in word doc.


Is anyone else having a bunch of issues with this after a recent windows update? I am getting the "Description: Word cannot complete the save due to a file permission error" error MUCH more frequently than I used to.

Any ideas?

Shanmukha priya V

Very nice function! Very useful!


It's great tool!
For those who want to save multiple figures, you can create those figures in a loop, and use this function inside the loop for each figure. It supports adding figures one after another.

Gopala Krishna Murthy

Very good


I am having the same issue as Anthony, below, only after updating to Matlab 2013a.


I tried adding a "for" loop so that multiple figures can be copied into word but it copies over the exiting plot. Any help?


Wonderful tools!!!


Please help with the following "invoke error" when I try to use a full file path to output the word document in an existing directory:

??? Invoke Error, Dispatch Exception:
Source: Microsoft Word
Description: This file could not be found.
Help File: C:\Program Files(x86)\Microsoft Office\Office12\1033\WDMAIN11.CHM
Help Context ID: 604e


The final result is different with matlab 2012.
The word file contain a picture and not a vector format.
Have you create an update?



Thanks Suresh... Its a very helpful program. It has saved a lot of time for me.

esya esya

It helped me finding way to read text data in the doc file.

Thanks a lot.


very good tool,thank you

Alex Frid

very handy! thanks!

>> save2word('junk.doc')
??? Invoke Error, Dispatch Exception:
Source: Microsoft Word
Description: This method or property is not available because the Clipboard is empty or not valid.
Help File: C:\Program Files\Microsoft Office\Office12\1033\WDMAIN11.CHM
Help Context ID: 91fd

Error in ==> save2word at 80

Anup Khekare

It works perfectly fine for me. I was looking for a way to code this, but this code here solves all the problems for me. Thank you very much. This helps to cut short the save figure and paste figure process.

Thanks Again.

Barbara Robson

If you replace "print -dmeta" with "uimenufcn(gcf,'EditCopyFigure')" you get exactly the image you'd get if you used Edit->Copy->Figure and pasted it manually: I find that this gives superior results for my purposes. For example, using uimenufcn gives me more control over the figure size and axis background color.

Lefteris Kaskavelis

I tried to use this code in MATLAB2007b in WindowsXP and I get the following message.
Invoke Error, Dispatch Exception:
Source: Microsoft Word
Description: This method or property is not available because the Clipboard is empty or not valid.
Help File: C:\Program Files\Microsoft Office\OFFICE11\1033\wdmain11.chm
Help Context ID: 91fd

Error in ==> save2word at 80

It used to work without problems in MATLAB2006b and Windows2000

Any ideas are welcome.

Thanks in advance

Dan Mikulskis

this is really handy. does exactly what i wanted.

Erik Larsen

I only tried this file b/c I ran into a matlab bug where I tried to copy a figure from the Edit->Copy Figure menu into word, but matlab was giving me an error (something about the figure handle not being valid, which was clearly a matlab bug). I spent a long time trying to find a workaround, but nothing worked well.

Suresh' script worked beautifully though, it generated a word file with the figure in there, exactly as it appeared in matlab (had to check 'match figure screen size' in the Edit->Copy Figure Options menu, though).

Licente Ro

I noticed in case one wants to automize this process and save multiple figures one after the other, there is a need to give some time to WORD to properly close both the file and

I intorduced some delay in the loop.
Initially I used 1 sec, but this is too low for my computer. With 2 sec works better.

Thanks again for this breaktrough info.

Ma Liang

I also have some error as below:
??? Invoke Error, Dispatch Exception:
Source: Microsoft Word
Description: ????????????
Help File: C:\Program Files\Microsoft Office\OFFICE11\2052\wdmain11.chm
Help Context ID: 62e2

Error in ==> WriteToWordFromMatlab>WordText at 198
actx_word_p.Selection.Style = style_p;

Error in ==> WriteToWordFromMatlab at 29
WordText(ActXWord,TextString,Style,[0,2]);%two enters after text

Sylvia Kohn-Rich

The error:
?? Invoke Error, Dispatch Exception:
Source: Microsoft Word
Description: This method or property is not available because the
Clipboard is empty or not valid.
Help File: C:\Program Files\Microsoft
Help Context ID: 91fd

can be avoided by using the following version:

function save2word(filespec,prnopt)

% SAVE2WORD saves plots to Microsoft Word.
% function SAVE2WORD(filespec,prnopt) saves the current Matlab figure
% window or Simulink model window to a Word file designated by
% filespec. If filespec is omitted, the user is prompted to enter
% one via UIPUTFILE. If the path is omitted from filespec, the
% Word file is created in the current Matlab working directory.
% Optional input argument prnopt is used to specify additional save
% options:
% -fHandle Handle of figure window to save
% -sName Name of Simulink model window to save
% Examples:
% >> saveppt
% Prompts user for valid filename and saves current figure
% >> save2word('junk.doc')
% Saves current figure to MS Word file called junk.doc
% >> save2word('junk.doc','-f3')
% Saves figure #3 to MS Word file called junk.doc
% >> save2word('models.doc','-sMainBlock')
% Saves Simulink model named "MainBlock" to file called models.doc
% The command-line method of invoking SAVEPPT will also work:
% >> save2word models.doc -sMainBlock
% If the figure has to be pasted as a smaller size bitmap, go to
% File->preferences->Figure Copy Template->Copy Options and
% check "Match Figure Screen Size" checkbox.
% Then make the figure small before by setting the position
% of the figure to a smaller size using
% set(gca,'Position',[xpos,ypos,width,height])
% Check also saveppt in Mathworks fileexchange

%Suresh E Joel, Mar 6,2003
%Virginia Commonwealth University
%Modification of 'saveppt' in Mathworks File Exchange
%and valuable suggestions by Mark W. Brown,

% Establish valid file name:
if nargin<1 | isempty(filespec);
[fname, fpath] = uiputfile('*.doc');
if fpath == 0; return; end
filespec = fullfile(fpath,fname);
[fpath,fname,fext] = fileparts(filespec);
if isempty(fpath); fpath = pwd; end
if isempty(fext); fext = '.doc'; end
filespec = fullfile(fpath,[fname,fext]);

% Start an ActiveX session with PowerPoint:
word = actxserver('Word.Application');
%word.Visible = 1;

if ~exist(filespec,'file');
% Create new presentation:
op = invoke(word.Documents,'Add');
% Open existing presentation:
op = invoke(word.Documents,'Open',filespec);

% Find end of document and make it the insertion point:
end_of_doc = get(word.activedocument.content,'end');

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

% Paste the contents of the Clipboard:


if ~exist(filespec,'file')
% Save file as new:
% Save existing file:

% Close the presentation window:

% Quit MS Word

% Close PowerPoint and terminate ActiveX:


Lee Barnea

nice useful tool. a bit problematic when the destination file is already opened

Jonathan Archer

Change the words 'PowerPoint' in the file to 'Word', perhaps.

I. Kalatzis


Fabien Lahoche

Very nice tool. Thks

Gang Huang


Kasper Paasch

Wonderfull tool. Just what I needed. Thanks.

Matthias Wetzel

Fine, wonderful tool.
Furthermore I'm searching for "own" report generator. This is one step to get it.

vishnu natesan

MATLAB Release Compatibility
Created with R12.1
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: saveppt

Inspired: WriteToWordFromMatlab, Quick_Figure, save2wordAllFigs

Community Treasure Hunt

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

Start Hunting!