Hi everyone, I'm working on a Matlab code that allows to write a report in MS word as follows (the following code has been written taking as reference Office VBA Reference and AI tools): clc; clear all; close all;
word = actxserver('Word.Application');
doc = word.Documents.Add(tmpl_path);
headings = doc.GetCrossReferenceItems(1)
heading_index = find(strcmp(headings, ' 2.1 TR-x-xxx'));
start_range = doc.Paragraphs.Item(heading_index).Range.Start;
end_range = doc.Paragraphs.Item(heading_index + 1).Range.End;
content_range = doc.Range(start_range, end_range);
Now I would like to copy an heading (TR-x-xxx) and its content (see the following image)
it follows as I would do in MS word if I didn't used Matlab:
Once selcted and copied, I would like to get the following result (I would like to be able to copy-paste and get as many headings+content as I want):
Is my code right? How do i proceed??
Edit
I've updated the last image since I forgot a detail: I want to put the copies before the section "Summary" and not at the end of my .docx
N.B. My document contains a Table of Contents with the " TR-x-xxx " string. This is an important detail since if the string search starts from the beginning of the document, I need to start the selection from the second occurrence.