I have a Microsoft Word document template that has insertion point bookmarks to indicate the location of where the desired fields are to be positioned.
In Word's object model I would get the range of a bookmark and add a field with the AddField method off of the range object. I use IncludeText fields that reference bookmarks in an external document.
I have created a small application that demonstrates this using two Microsoft Word files located under the project's Data folder.
These solution consists of a Word document used as a data source(Data Sheet.docx), with information elements bookmarked to identify the underlying data. The document template, FormLetter.dotx, is bookmarked with insertion point bookmarks to indicate where data fields are to be inserted. This apporach enables changes in the underlying data (stored in the Word document used as the data source) to be updated in one location and have those changes be reflected in all of the documents that have already been generated and possibly edited by simply updating the fields of the generated document.
Data from the Data Source document is inserted into the generated documentation as INCLUDETEXT fields that reference the bookmarked data in the data source document.
I need to be able to insert a field at the precise location of an insertion point bookmark (one that in the Word object model has a Range property with a Start and End that are equal).
In looking at the documentation for DocIO, it appears that fields can only be appended to paragraphs. Bookmarks in DocIO do not have a Range concept quite the same as Word.
This reproduction app contains a Data Sheet.docx file that contains two pieces of information identified by the bookmarks FirstName and LastName. There is a document template file named FormLetter.dotx that contains text with two bookmarks that indicate where I would like to insert fields in the generated document, CompletedFormLetter.docx.
When you build and run the reproduction application and press the Go button, you will observe Microsoft Word opening the generated document and the fields are located at the end of the paragraph instead of at the desired bookmark locations.
Attachment:
InsertFieldAtBookmarkLocation_34925c91.zip