How to retrieve CustomDocumentProperties from Microsoft Word?

2 views (last 30 days)
Matlab provides the means to interact with Microsoft Office programs via several interfaces. I'm currently trying to interact with MS Word via the ActiveX or .Net interfaces. Specifically, I'm trying to retrieve and edit CustomDocumentProperties. These are basically properties the user has added themselves in the MS Word application.
ActiveX approach:
%% Connect to word
Word = actxserver('word.application');
%% Open a template file
WordObj = Word.Documents.Open(fullfile(pwd,'test.docx'));
%% "Unlock" the CustomDocumentProperties
CDP = WordObj.CustomDocumentProperties;
So far so good. I can retrieve the correct number of Custom properties that have been added in the template Word file:
However, I'm stuck this point onwards. It seems I cannot go further than this. What syntax should I use to get or set one of these properties? The properties are approachable via VBA, but not via Matlab or so it seems.
.NET approach:
WordDocObj = mlreportgen.utils.WordDoc("test.docx") % Note, .docm not allowed
Document = netobj(WordDocObj);
This produces the following error:
ans =
__ComObject with no properties.

Answers (1)

Andrea Carignano
Andrea Carignano on 10 Mar 2021
Edited: Andrea Carignano on 10 Mar 2021
Hi Marcel,
Suppose you have a custon property "MyCustomProperty".
You can use this code to get the property object
PropertyObject = get(CDP,'Item','MyCustomProperty');
To get the propery value
PropertyValue = get(PropertyObject,'Value');
To set the property value
set(PropertyObject,'Value','Your property value');




Community Treasure Hunt

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

Start Hunting!