ActiveQt and word. Writing to an opened word document ?
-
I am trying to write to an open word document using ActiveQt. I am able to write to my word document (.doc) if it is closed, my code will open the document and then start writing to it. But if the document is already open it opens a read-only copy and not the original document. From what I have read it should be possible to activate an open word document and then start writing to it, but I cant get it to work with Qt. This is how I open the document:
@QAxObject * doc;
QAxObject* wordApplication;
wordApplication = new QAxObject("Word.Application",this);
doc = wordApplication->querySubObject("Documents()");
doc->dynamicCall("Open(QVariant,QVariant,QVariant,QVariant,QVariant,QVariant,QVariant)","c:/my.doc",false,false,false,"","",false); @Setting Revert to false, which is the 7th argument for the Open method, should do the following according to the word developer reference: Controls what happens if FileName is the name of an open document. True to discard any unsaved changes to the open document and reopen the file. False to activate the open document. For me it does not activate the open document, but opens a read-only copy and starts writing to that.
I have found a VBA code that does what I want:
@Documents("my.doc").Activate@I have tried making a corresponding code using ActiveQt without luck. I need to do something similar in my Qt code, any help would be greatly appreciated.
-
did you try it like this?
@
doc = wordApplication->querySubObject("Documents(QString)","c:/my.doc");
doc->dynamicCall("Activate()");
@ -
Yes, I have tried that without luck. Documents(QString) is empty, and it can't find "c:/my.doc". When im running this in VBA Documents() is a list containing all the currently open word documents, but when I try to do this in Qt it is empty and I don't understand why.
Did you get it to work with that code ?
-
bq. Did you get it to work with that code ?
No, I didn't test it.I just found out that creating the application object creates a new Word process (look in the task manager) and the documents collection doesn't include the documents of other word-processes.
-
Ok, that is a good find. Is there any way to create a documents() object without first creating a new word.application object ?