Question

I have run into an interesting problem with the current application I'm working on in Delphi. The problem is that in certain circumstances the ActiveDocument of our TWordApplication can be changed before the document is completed.

I have a TWordApplication (WordApp) and a TWordDocument (WordDoc) which are initialised as below:

WordApp.Connect;
WordApp.Documents.Add(Template, EmptyParam, EmptyParam, EmptyParam);
WordApp.ChangeFileOpenDirectory(jdir);
WordDoc.ConnectTo(WordApp.ActiveDocument);

Mostly I then update some bookmarks or insert text from a number of templates:

Range := '';
convert := msoFalse;
LinkFile := msoFalse;
Attach := msoFalse;
WordApp.Selection.InsertFile(Template, Range, Convert, LinkFIle, Attach);

In one workflow the creation of the document is interrupted by the creation of a second document. If this document is not closed after saving then it "steals" focus from the original. I think that it is legitimate that the user shouldn't need to remember to close down the second document.

What I want to do is either switch the focus of WordApp to WordDoc or alternatively use WordDoc directly for the InsertFile - but this doesn't seem to be an option.

(There is a third option where I collate the required data for the second document before I create the first document, but that will require a change in application logic.)

Any help?

Was it helpful?

Solution

In the end I rewrote the logic to prepare the second document earlier in the workflow, meaning I can compile the final document uninterrupted.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top