Word document "Saveas2()" method no longer working

As of the past few days, I seem to be no longer able to save word documents created through matlab. Several months ago I ran the following script which opens an existing word document and saves it as another document.
reportPath = 'Table_out.docx';
templateName = append(pwd, '\Table_Inject_Test.docx');
actx_word = actxserver('Word.Application');
Execution of script actxserver as a function is not supported:
/MATLAB/toolbox/matlab/winfun/actxserver.m
actx_word.Visible = true;
trace(actx_word.Visible);
wordTemplate = actx_word.Documents.Open(templateName); % Open template
wordTemplate.SaveAs2(reportPath); % Save copy as report
Once I started getting this error in another project, I reverted back to this script to check it wasn't something I had done within the word template to cause the error.
However when I try to run the same script now, I get the following error:
% Unrecognized method, property, or field 'SaveAs2' for class
% 'Interface.0002096B_0000_0000_C000_000000000046'.
% Error in tableinjecttest2 (line 7)
% wordTemplate.SaveAs2(reportPath); % Save copy as report
Has something changed within the WordInterface object? I see there is a 'saveobj' method but that doesn't seem to save the document either. That just gives me a different error:
% Unable to resolve the name 'wordParent.saveobj'.
%
% Error in tableInjectTest (line 22)
% wordTemplate.saveobj(reportPath)

4 Comments

That the error seems to think the function is a script implies there must be an alias or the builtin function has been inadvertently overwritten.
See what
which -all actxserver
returns; if there is more than the one in the winfun toolbox folder, then that will be the problem...remove/rename it to not clash.
If there isn't the alias, see what
type actxserver
shows...it should show that the builtin is indeed, a function starting off something like
>> type actxserver.m
function h = actxserver(progID, varargin)
%ACTXSERVER Creates a COM Automation server.
% H = ACTXSERVER('PROGID') Creates a local or remote COM Automation server
% where PROGID is the programmatic identifier of the COM server and H is
% the handle of the server's default interface.
that it is, indeed, a function, not a script. It not, something is munged...
Everything seems above board within my matlab itself. Entering:
which -all actxserver
gives me:
built-in (C:\Program Files\MATLAB\R2024a\toolbox\matlab\winfun\actxserver)
and running:
type actxserver.m
gives out:
%ACTXSERVER Creates a COM Automation server.
% H = ACTXSERVER('PROGID') Creates a local or remote COM Automation server
% where PROGID is the programmatic identifier of the COM server and H is
% the handle of the server's default interface.
%
% H = ACTXSERVER('PROGID', 'param1', value1,...) creates an ActiveX
% server with optional parameter name/value pairs. Parameter names are:
% machine: specifies the name of a remote machine on which to launch
% the server.
the only difference I'm seeing between your output and mine is that the function h = actxserver(progID, varargin) text doesn't appear at the top of the output. My colleague is also experiencing the exact same issue which leaves to me believe its something to do with actxserver itself.
"... function h = actxserver(progID, varargin) text doesn't appear at the top of the output."
That's because built-in functions don't have the source code available as with the m-file.
This then is a bug when Mathworks built/shipped the builtin version. Submit an official bug report..
If you have an earlier release, a temporary workaround could be to copy the m-file into a location on your working path above the toolboxes to use the prior version instead.
Looks like it was fixed this morning, good to know for the future. Thanks.

Sign in to comment.

Answers (0)

Products

Release

R2024a

Asked:

on 18 Jun 2025

Commented:

on 19 Jun 2025

Community Treasure Hunt

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

Start Hunting!