Read/Write MS Word document properties with ActiveX
Solved
General and Desktop
-
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
-
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