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. QAxObjects issue with Office 365?

QAxObjects issue with Office 365?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 384 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.
  • P Offline
    P Offline
    Pauly
    wrote on last edited by Pauly
    #1

    I'm using QAxObjects to interact with excel, here is the code:

    QAxObject* pApp = new QAxObject("Excel.Application", 0);
    pDoc = pApp->querySubObject("Workbooks");
    pContent = pDoc->querySubObject("Open(QString)", QDir::toNativeSeparators(path));
    pVBProject=pContent->querySubObject("VBproject");
    pVBComponent=pVBProject->querySubObject("VBComponents");
    
    int macroCount = pVBComponent->property("Count").toInt();
    for (int i=1; i<=macroCount; i++) {
    
        qDebug()<<QString("Module #%1 of #%2").arg(i).arg(pVBComponent->property("Count").toInt()));
        
        QAxObject* module = pVBComponent->querySubObject("Item(int)", i);
        if(module==nullptr) continue;
    
        qDebug()<<QString("Module \"%1\"").arg(module->property("Name").toString());
    
        QAxObject* codeModule = module->querySubObject("CodeModule");
        if(codeModule==nullptr) continue;
        int lineCount=codeModule->property("CountOfLines").toInt(); //<----pVBComponent->property("Count").toInt() will return 0 if placed after this point, only happen for Office 365, what is wrong?
    
        qDebug()<<QString("%1 lines").arg(lineCount);
    }
    

    Everything works as expected in Office 2016, but not in Office 365, where I get:

    Module #1 of #7
    Module "Module1"
    0 lines
    Module #2 of #0
    Module #3 of #0
    Module #4 of #0
    Module #5 of #0
    Module #6 of #0
    Module #7 of #0

    After some poking, pVBComponent is actually lost (?) in the lineCount call as indicated above in the first loop. This only happens with Office 365. What is wrong? Thanks.

    Also there is an issue with SaveAs in Office 365:

    pContent->dynamicCall("SaveAs(QString)", path);
    

    this will always fails, but in Office 2016 and other office version it will work fine. Are these all related?

    JonBJ 1 Reply Last reply
    0
    • P Pauly

      I'm using QAxObjects to interact with excel, here is the code:

      QAxObject* pApp = new QAxObject("Excel.Application", 0);
      pDoc = pApp->querySubObject("Workbooks");
      pContent = pDoc->querySubObject("Open(QString)", QDir::toNativeSeparators(path));
      pVBProject=pContent->querySubObject("VBproject");
      pVBComponent=pVBProject->querySubObject("VBComponents");
      
      int macroCount = pVBComponent->property("Count").toInt();
      for (int i=1; i<=macroCount; i++) {
      
          qDebug()<<QString("Module #%1 of #%2").arg(i).arg(pVBComponent->property("Count").toInt()));
          
          QAxObject* module = pVBComponent->querySubObject("Item(int)", i);
          if(module==nullptr) continue;
      
          qDebug()<<QString("Module \"%1\"").arg(module->property("Name").toString());
      
          QAxObject* codeModule = module->querySubObject("CodeModule");
          if(codeModule==nullptr) continue;
          int lineCount=codeModule->property("CountOfLines").toInt(); //<----pVBComponent->property("Count").toInt() will return 0 if placed after this point, only happen for Office 365, what is wrong?
      
          qDebug()<<QString("%1 lines").arg(lineCount);
      }
      

      Everything works as expected in Office 2016, but not in Office 365, where I get:

      Module #1 of #7
      Module "Module1"
      0 lines
      Module #2 of #0
      Module #3 of #0
      Module #4 of #0
      Module #5 of #0
      Module #6 of #0
      Module #7 of #0

      After some poking, pVBComponent is actually lost (?) in the lineCount call as indicated above in the first loop. This only happens with Office 365. What is wrong? Thanks.

      Also there is an issue with SaveAs in Office 365:

      pContent->dynamicCall("SaveAs(QString)", path);
      

      this will always fails, but in Office 2016 and other office version it will work fine. Are these all related?

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @Pauly
      I see your problem. I don't know the answer, and don't know that you'll get an answer here.

      I will say that when I have used Automation from other products which have a interface like QAxObject I found it very useful to design/test my code from MS VBA/within Excel etc., rather than from the product, and then translate the VBA to the product's syntax when ready. If you feel like doing that here, you should check whether the native VBA code in Excel shows the same behaviour as you are witnessing, then it's not a QAxObject issue.

      P 1 Reply Last reply
      1
      • JonBJ JonB

        @Pauly
        I see your problem. I don't know the answer, and don't know that you'll get an answer here.

        I will say that when I have used Automation from other products which have a interface like QAxObject I found it very useful to design/test my code from MS VBA/within Excel etc., rather than from the product, and then translate the VBA to the product's syntax when ready. If you feel like doing that here, you should check whether the native VBA code in Excel shows the same behaviour as you are witnessing, then it's not a QAxObject issue.

        P Offline
        P Offline
        Pauly
        wrote on last edited by
        #3

        @JonB I tried this in VBA in Office 365 and it works:

        count=ActiveWorkbook.VBProject.VBComponents(1).CodeModule.CountOfLines
        

        So this is likely a Qt issue? And does it make sense if it works with all other Office version but not Office 365? Something special about Office 365?

        JonBJ 1 Reply Last reply
        0
        • P Pauly

          @JonB I tried this in VBA in Office 365 and it works:

          count=ActiveWorkbook.VBProject.VBComponents(1).CodeModule.CountOfLines
          

          So this is likely a Qt issue? And does it make sense if it works with all other Office version but not Office 365? Something special about Office 365?

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @Pauly
          I don't know, but I guess it does point more towards a Qt issue than VBA. It does look a bit like that pVBComponent is going walkies, somehow. As for difference between 365 vs 2016, who knows, the code/requirements may be different.

          Dunno, try copying your setting of pVBProject & pVBComponent to inside the loop each time round. Yes, you shouldn't have to do that, but does it make any difference? Maybe do some debugging to see which precise variable it is that "goes walkies", though not sure what you're going to do with information. You're look for a "workaround" which simply works for you.

          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