I got an interesting problem when using ole-automation to insert content to existing word documents using code like this:
WordApp.Selection.HomeKey(unit := wdStory);
if FileExists(s) then
WordApp.Selection.InsertFile(Filename := s, ConfirmConversions := false,
Link := false, Attachment := false);
This works quite well with most word-documents, except those where we got an "automatic table of Content" as first element in the document. In this case the automation crashes with:
This action is not valid outside of a block-level XML
I tried some other functions like:
WordApp.Selection.InsertText('Test') / (#13#10)
WordApp.Selection.InsertBreak(Page/Line)
with the same negative result. It seems that the Cursor Position is invalid when the first element is that automatic table.
Any ideas how I can fix this on my side?