Excel sheet selection with COM C++ RRS feed

  • Question

  • Hello,
    There is a great example for writing data to Excel with COM: import

    But the problem is that there the data is write in the active sheet, but i need a write not active, that is, i need to select a sheet for writing.

    But unfortunately I can not understand how to change the code for this.

    In theory, it is necessary, as it is, to replace the pXlSheet parameterwith one that is needed, but I cannot understand how to do it:

      // Get ActiveSheet object
       IDispatch *pXlSheet;
          VARIANT result;
          AutoWrap(DISPATCH_PROPERTYGET, &result, pXlApp, L"ActiveSheet", 0);
          pXlSheet = result.pdispVal;
       // Get Range object for the Range A1:O15...
       IDispatch *pXlRange;
          VARIANT parm;
          parm.vt = VT_BSTR;
          parm.bstrVal = ::SysAllocString(L"A1:O15");
          VARIANT result;
          AutoWrap(DISPATCH_PROPERTYGET, &result, pXlSheet, L"Range", 1, parm);
          pXlRange = result.pdispVal;

    If not difficult, please tell me how this can be done.

    Monday, March 4, 2019 11:32 AM