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. Read/Write MS Word document properties with ActiveX

Read/Write MS Word document properties with ActiveX

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 1.4k Views
  • 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 Offline
    W Offline
    wuthrich
    wrote on 22 Jan 2018, 14:24 last edited by wuthrich
    #1

    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
    1
    • W Offline
      W Offline
      wuthrich
      wrote on 23 Jan 2018, 01:29 last edited by wuthrich
      #2

      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
      3

      2/2

      23 Jan 2018, 01:29

      • Login

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