again: Getting an existing instance of Excel

  • Nobody/Anonymous


    I have this "get existing instance of excel" problem, i find the post:, but doesn't have answer since 2006, is this feature availabe in the 2.2.4 version? is there an example?



    • Nobody/Anonymous

      I changed this function in callCom.cpp to do this. Not sure if its worth it. the lack of array support in jcom is a real major limitation.

      HRESULT createInstance(const char* progid, IDispatch** ppIDispatch)
          HRESULT hr = CoInitialize(NULL);
          if(FAILED(hr)) return hr;

          CLSID clsid;
      //    hr = CLSIDFromProgID(T2OLE((LPCSTR)progid), &clsid);
          hr = CLSIDFromProgID(A2COLE(progid), &clsid);
          if(FAILED(hr)) return hr;

          *ppIDispatch = NULL;    // ”O‚Ì‚½‚ß
      /* orig
          hr = CoCreateInstance(clsid, NULL, CLSCTX_SERVER,
                              IID_IDispatch, (void**)ppIDispatch);
          // My version that only opens if its not already open
          // Get an interface to the running instance, if any..
          IUnknown *pUnk;
          hr = GetActiveObject(clsid, NULL, (IUnknown**)&pUnk);

              // Get IDispatch interface for Automation...
              hr = pUnk->QueryInterface(IID_IDispatch, (void **)ppIDispatch);
          // Release the no-longer-needed IUnknown...

          if(hr != S_OK)
              hr = CoCreateInstance(clsid, NULL, CLSCTX_SERVER,
              IID_IDispatch, (void**)ppIDispatch);

          return hr;

  • TADev

    TADev - 2010-06-09

    We've been using the 2.2.4 jar - I'm going to try your change to the cpp source, and build. Thanks.


Log in to post a comment.