Thanks for your answer, it actually works great but there’s something still not ok for my needs…
Let me explain :
In the document, I have some fields that act like opening and closing tags. So the doc will look like this :
BEGIN_SECTION_1
Some text here...
BEGIN_SECTION_2 Another text END_SECTION_2
Another text here or maybe we can insert some "real" fields
END_SECTION_2
The idea is that the user will place the cursor where he wants to insert a field.
The macro is supposed to check its position : if the cursor is outside of a “section” then user won’t be able to add any field.
In the other case, the macro will search inside a database, and depending on the section, some fields will be presented to the user. Then he will have to choose one, click, and the field will be inserted.
The last part, I was able to write the code, because I already add the code to insert the sections, and sections are also fields.
My problem here is when I run your code, the array of fields that I get is not in the same order as the fields that are on the page.
In the example I gave you, if my cursor is inside section 2, then I was expecting to retrive the field “BEGIN_SECT_1” and then “BEGIN_SECTION_2”. So I would just get the last item of the array (BEGIN_SECT_2) and I would know that user is inside section 2, and I could run my query to get the available fields.
But when I run your code, the fields are not in this order…
The array contains the list of the fields that are inside the document, from the beginning until the cursor, that’s true, that was my question, but I forgot to say “in the same order as they appear on the page”.
Is it something that can be done ?