How move selection through a .docx document from Matlab?
7 views (last 30 days)
Show older comments
Hello everyone, I've to write a report in MS word from Matlab and I'm using actxserver('Word.Application') and, despite of some material found on the internet, I can't move the selection to a given point of my document. I load a template .docx I subsequently need to modify and interact with.
Here is my MWE (it doesn't work since I am not allowed to upload .docx file)
% Template path
tmpl_path = 'C:\Users\user_name\Desktop\template_report.docx'
% Create a new Word document from the template
word = actxserver('Word.Application'); % it's a Matlab function
word.visible=1;
doc = word.Documents.Add(tmpl_path);
Tried to use the following command based on this documentation
word.Selection.GoTo(4, 1, [], [])
In the command window I get "ans = Interface.0002095E_0000_0000_C000_000000000046". But in the .docx window the selection is standstill at the beginning of the document
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1691741/image.png)
while I need to move it at the beginning of the second section.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1691746/image.png)
0 Comments
Answers (2)
Mario Malic
on 10 May 2024
You have mistaken WdGoToItem enumeration, number 4 is for footnote. You need 0 or 11.
0 Comments
See Also
Categories
Find more on MATLAB Report Generator 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!