Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Solved Read/Write MS Word document properties with ActiveX

    General and Desktop
    1
    2
    1087
    Loading More Posts
    • 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.
    • W
      wuthrich last edited by wuthrich

      Hello everyone

      I am trying to access to the document properties from MS Word using ActiveX
      Following the documentation from Microsoft (https://msdn.microsoft.com/en-us/vba/word-vba/articles/document-builtindocumentproperties-property-word) I managed to read, for example the document author property, using this code:

      // New word application
      QAxObject* word = new QAxObject("Word.Application", 0 );
      // Get access to the documents
      QAxObject* docs = word->querySubObject("Documents");
      
      // Configure parameters for opening a word file
      QVariant filename(fileName);
      QVariant confirmconversions(false);
      QVariant readonly(false);
      QVariant addtorecentfiles(false);
      QVariant passworddocument("");
      QVariant passwordtemplate("");
      QVariant revert(false);
      doc = docs->querySubObject("Open(QVariant,QVariant,QVariant,QVariant,QVariant,QVariant,QVariant)",
                    filename, confirmconversions, readonly, addtorecentfiles, passworddocument, passwordtemplate, revert);
      
      // Get access to the Author document property of the opened file
      QAxObject* auth = doc->querySubObject("BuiltInDocumentProperties(\"Author\")");
      // read the value of the property
      QString author = auth->dynamicCall("Value()").toString();
      

      But I have no idea how to write this author property (e.g. to set a new author name Joe Smith)

      Thank you for any input that would direct me to the right answer

      1 Reply Last reply Reply Quote 1
      • W
        wuthrich last edited by wuthrich

        I finally found a way to do it. To set a property (e.g. the Author property) use:

        auth->dynamicCall("Value",  "Joe Smith");
        

        This link gives insights on this:
        http://doc.qt.io/qt-5/qaxbase.html#dynamicCall

        1 Reply Last reply Reply Quote 3
        • W
          wuthrich last edited by wuthrich

          I finally found a way to do it. To set a property (e.g. the Author property) use:

          auth->dynamicCall("Value",  "Joe Smith");
          

          This link gives insights on this:
          http://doc.qt.io/qt-5/qaxbase.html#dynamicCall

          1 Reply Last reply Reply Quote 3
          • First post
            Last post