Skip to content
  • 0 Votes
    8 Posts
    1k Views
    U

    Noticed another feature (word 2007).
    Created this app:

    #include "mainwindow.h" #include "ui_mainwindow.h" #include <ActiveQt/QAxObject> #include <ActiveQt/qaxbase.h> #include <QDir> QAxObject *word, *objVBComp, *objCodeMod; QString VbaScriptLine = "Sub MacroCreatedByUser() : ActiveDocument.VBProject.References.AddFromGuid \"{00020802-0000-0000-C000-000000000046}\", 1, 5 : End Sub"; QString OpenFilePath = "input.doc"; QString SaveFilePath = "output.doc"; QString MacroName = "Test macros"; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); } MainWindow::~MainWindow() { delete ui; } void MainWindow::on_pushButton_pressed() { word = new QAxObject( "Word.Application" ); word->setProperty("DisplayAlerts", - 1); word->setProperty("Visible", true); QString PathTmp = QDir::toNativeSeparators(QDir::currentPath() + "\\" + OpenFilePath); word->querySubObject( "Documents()" )->dynamicCall( "Open(FileName, ConfirmConversions, ReadOnly )", QDir::toNativeSeparators(QDir::currentPath() + "\\" + OpenFilePath), false, false ); objCodeMod = word->querySubObject( "ActiveDocument" )->querySubObject( "VBProject" )->querySubObject( "VBComponents" )->querySubObject("Item(Index)", 1)->querySubObject( "CodeModule" ); objCodeMod->dynamicCall( "AddFromString(QString)", VbaScriptLine ); word->querySubObject( "Application" )->dynamicCall( "Run(MacroName)", MacroName ); word->querySubObject( "ActiveDocument" )->dynamicCall( "SaveAs( FileName, FileFormat )", QDir::toNativeSeparators(QDir::currentPath() + "\\" + SaveFilePath), 0 ); word->querySubObject( "ActiveDocument" )->dynamicCall( "Close(SaveChanges)", 0 ); word->dynamicCall( "Quit()" ); delete word; }

    While executing the line: «objCodeMod->dynamicCall( "AddFromString(QString)", VbaScriptLine );» Windows OS fixes an error in the WINWORD.EXE application:
    win_error.png

    Despite the error, the macro is added and called as expected.

  • 0 Votes
    7 Posts
    768 Views
    S

    Yes @JonB, it requires depencencies but this is not a problem. I will install this automaticly after users choice.

    You can find them under:
    LTS RELEASE
    https://dotnet.microsoft.com/download/dotnet-core/3.1

    Current release
    https://dotnet.microsoft.com/download/dotnet/5.0

    Note: .net CORE works with Linux, macOS und Windows.

  • 0 Votes
    7 Posts
    885 Views
    S

    @mrjj
    Thanks for the response.
    So is there any way i could generate a word doc report with multiple pages of different sizes or i already have a pdf file generated. Can i convert the pdf file to doc format in qt ?(in that case i dont have to generate textdoc itself)..Is there any reliable 3rd party library as such?

    Thank you

  • 0 Votes
    10 Posts
    3k Views
    EddyE

    You're welcome

    Eddy