Board index » delphi » Help - Excel in OleContainer does not coexist with other Excel instances

Help - Excel in OleContainer does not coexist with other Excel instances

Hi -

I am developing an application which uses Excel in an OLEContainer.
It seems to be working well except for one problem - I want it to
coexist cleanly with other instances of Excel which might be running
at the same time.  This means that:

    -- if Excel was already running on the user's machine, I want my
        app to leave it alone and create a fresh instance for my container.

    -- if my app is running, the user should be able to open Excel on the
        side without connecting to the one in my application

This is easy to do with straight OLE Automation, but I can't find any
way to force the container to do it.  If I do a CreateObjectFromFile,
I connect to the currently running instance; if I do a CreateObject of
excel.application, I get a new instance, but I can't convince it to
display anything...

I would be grateful for any suggestions...

Thanks,
    -- leon

----------------------------
( sorry for the anti-spam address - I am really lgordon at osinj.com)

 

Re:Help - Excel in OleContainer does not coexist with other Excel instances


Quote
noSpam wrote in message <361C26DE.EEF48...@nowhere.com>...
>Hi -

>I am developing an application which uses Excel in an OLEContainer.
>It seems to be working well except for one problem - I want it to
>coexist cleanly with other instances of Excel which might be running
>at the same time.  This means that:

>    -- if Excel was already running on the user's machine, I want my
>        app to leave it alone and create a fresh instance for my container.

>    -- if my app is running, the user should be able to open Excel on the
>        side without connecting to the one in my application

>This is easy to do with straight OLE Automation, but I can't find any
>way to force the container to do it.  If I do a CreateObjectFromFile,
>I connect to the currently running instance; if I do a CreateObject of
>excel.application, I get a new instance, but I can't convince it to
>display anything...

>I would be grateful for any suggestions...

>Thanks,
>    -- leon

>----------------------------
>( sorry for the anti-spam address - I am really lgordon at osinj.com)

In the C++Builder examples that use OLE, the following code and comments is
always included.  It makes me think that Excel checks to see if it is
already running.

-- this snipit is excerpted from ...\Examples\Doc\OLEWord2\MAIN.CPP --
    //check that this automation routine is not already executing.  A single
    //instance of Word seems not to like it.
    shFileMap = CreateFileMapping((HANDLE)0xffffffff,
                                  NULL,
                                  PAGE_READWRITE,
                                  0,
                                  4,
                                  "OLEWord2SharedData");
    if (shFileMap != NULL && GetLastError() == ERROR_ALREADY_EXISTS){
    throw Exception( "This automation procedure seems be running already.
Aborting Automation.");
    }

    V = CreateOleObject("Word.Basic");

Other Threads