How to change the internal properties of a Word Document from MATLAB R2012b?

17 views (last 30 days)
I am using ACTXSERVER to initialize a COM component and have created a Microsoft Word document. I know how to change the TEXT or FONT of the document but I would like to know if there is a way to change the internal Properties of a Word Document like the AUTHOR or the TITLE.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 20 Feb 2023
Edited: MathWorks Support Team on 16 Apr 2023
Please refer to the code below regarding the issue. The code has been written with respect to the property called ‘Author’. You can make the changes according to other properties.
Please refer to the following link for more information,
The above link provides example using Excel but you can use the syntax for Word as well.
Also, MATLAB only provides an interface for users between MATLAB and Microsoft Word. Due to limited resources at our hand we would not be able to provide the perfect solution to this issue. Please direct your questions towards Microsoft Technical Support for an expert advice on this issue.
% Connect to Word
hdlActiveX = actxserver('Word.Application');
hdlActiveX.Visible = true;
% Create a new document
hdlWordDoc = invoke(hdlActiveX.Documents, 'Add');
% make the document visible
trace(hdlActiveX.Visible);
% Intialize a handle for the built-in property 'Author'
hdl = get(hdlWordDoc.builtInDocumentProperties, 'Item', 'Author')
% Get Author
get(hdl,'Value')
% Set Author
set(hdl,'Value','newAuthor')
% Save the WORD document
hdlWordDoc.SaveAs2('trial.doc')
% Close objects
hdlWordDoc.Close();
hdlActiveX.Quit();

More Answers (0)

Products


Release

R2012b

Community Treasure Hunt

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

Start Hunting!