Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. ActiveQt and word. Writing to an opened word document ?
Forum Updated to NodeBB v4.3 + New Features

ActiveQt and word. Writing to an opened word document ?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 3.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ActiveQtman
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chris17
      wrote on last edited by
      #2

      did you try it like this?
      @
      doc = wordApplication->querySubObject("Documents(QString)","c:/my.doc");
      doc->dynamicCall("Activate()");
      @

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ActiveQtman
        wrote on last edited by
        #3

        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 ?

        1 Reply Last reply
        0
        • C Offline
          C Offline
          chris17
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            ActiveQtman
            wrote on last edited by
            #5

            Ok, that is a good find. Is there any way to create a documents() object without first creating a new word.application object ?

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved