How to use ActiveX to change MS Word Table properties
Show older comments
I am trying to edit the properties of a table I create in MS Word via ActiveX control in MATLAB and running into difficulties.
Pretty much everywhere I look, people just point to the Microsoft Word object model for Visual Basic help page (https://learn.microsoft.com/en-us/office/vba/api/overview/Word/object-model) and a few example codes (https://www.mathworks.com/matlabcentral/fileexchange/56283-activex-word-control-base-commands?s_tid=FX_rc2_behav and https://www.mathworks.com/matlabcentral/fileexchange/9112-writetowordfrommatlab). My issue is when I try to follow the pattern setout in these examples for implementing the properties on the VB website, MATLAB says "Undefined function" for nearly all of the properties listed.
Based on the discussion on a few other questions posted (e.g. https://www.mathworks.com/matlabcentral/answers/402024-activex-syntax-for-word-tables-cursor-position-sub-tables-etc#answer_321964) , would expect that they should all work. What am I missing? I am a relative newbie with this stuff, so I am most likely just misunderstanding something fundamental here. As an example, why does the following code not let me change the property for table borders (https://learn.microsoft.com/en-us/office/vba/api/word.table.borders):
actx_word = actxserver('Word.Application');
actx_word.Visible = true;
trace(actx_word.Visible);
% Open existing document:
filePath = 'C:\Example.doc';
word_handle = invoke(actx_word.Documents,'Open',filePath);
nr_rows = 2;
nr_rows = 4;
actx_word.ActiveDocument.Tables.Add(actx_word.Selection.Range,nr_rows,nr_cols,1,1);
% Try to change Border thickness
actx_word.ActiveDocument.Tables.Borders.OutsideLineStyle = 'wdLineStyleDouble';
% populate the table with content
for r=1:nr_rows
for c=1:nr_rows
actx_word.Selection.TypeText(['(',num2str(r),',',num2str(c),')']);
actx_word.Selection.MoveRight;
end
end
The error it throws at the line that tries to change Border thickness:
Undefined function 'Borders' for input arguments of type
'Interface.0002094D_0000_0000_C000_000000000046'.
Error in untitled2 (line 23)
actx_word.ActiveDocument.Tables.Borders.OutsideLineStyle
= 'wdLineStyleDouble';
Accepted Answer
More Answers (0)
Categories
Find more on Use COM Objects in MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!