OLE with Excel.

Post Reply
byron.hopp
Posts: 388
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA
Contact:

OLE with Excel.

Post by byron.hopp »

I find many problems with using OLE with Excel. I believe it is because Excel is running in the background when I attempt to launch a new instance. I attempted to use IsExeRunning("Excel",".",.f.) including many versions with case "EXCEL", and "excel" and it seems it reports accurately on the first call, but incorrectly for every call after. Is there a better way to detect if an executable is running on a workstation?

Thanks,
Thanks,
Byron Hopp
Matrix Computer Services
User avatar
Enrico Maria Giordano
Posts: 8766
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 5 times
Contact:

Re: OLE with Excel.

Post by Enrico Maria Giordano »

Can you prepare a little sample showing the problem that can be compiled and run?
byron.hopp
Posts: 388
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA
Contact:

Re: OLE with Excel.

Post by byron.hopp »

Just pop this into any app that has a menu so you can call it multiple times without terminating the app.

Function McsExcelRunning()
If IsExeRunning( "excel",".",.F. )
MsgStop( "Excel is currently running...","IsExeRunning" )
Else
MsgInfo( "Excel is not running...","IsExeRunning" )
Endif
Return nil
Thanks,
Byron Hopp
Matrix Computer Services
User avatar
Enrico Maria Giordano
Posts: 8766
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 5 times
Contact:

Re: OLE with Excel.

Post by Enrico Maria Giordano »

This is a working sample:

Code: Select all | Expand

#include "Fivewin.ch"


FUNCTION MAIN()

    ? EXELRUNNING()
    ? EXELRUNNING()

    RETURN NIL


STATIC FUNCTION EXELRUNNING()

    LOCAL lRun := .F.

    TRY
        GETACTIVEOBJECT( "Excel.Application" )
        lRun = .T.
    CATCH
    END

    RETURN lRun
byron.hopp
Posts: 388
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA
Contact:

Re: OLE with Excel.

Post by byron.hopp »

Thank you, I will give this a shot.
Thanks,
Byron Hopp
Matrix Computer Services
byron.hopp
Posts: 388
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA
Contact:

Re: OLE with Excel.

Post by byron.hopp »

Works Great, Thank you,
Thanks,
Byron Hopp
Matrix Computer Services
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

Re: OLE with Excel.

Post by Jimmy »

hi Byron,
byron.hopp wrote:I believe it is because Excel is running in the background when I attempt to launch a new instance.

how do you "close" OLE Connection to Excel ?

Code: Select all | Expand

  // Start Excel
   oExcel := CreateObject( "Excel.Application" )

   ...

   // Quit Excel
   oExcel:Quit()
   // destroy the reference
   oExcel:destroy()
   oExcel := NIL
   IF ComLastError() > 0
greeting,
Jimmy
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

Re: OLE with Excel.

Post by Jimmy »

hi,

i´m not sure how under FiveWin but it is recommend to o:Destroy() -> o:End() an ActiveX "Connection" and NIL it

o:Quit() is like close Firefox but still have Internet "Connection"
greeting,
Jimmy
User avatar
nageswaragunupudi
Posts: 10729
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 10 times
Contact:

Re: OLE with Excel.

Post by nageswaragunupudi »

byron.hopp wrote:I find many problems with using OLE with Excel. I believe it is because Excel is running in the background when I attempt to launch a new instance. I attempted to use IsExeRunning("Excel",".",.f.) including many versions with case "EXCEL", and "excel" and it seems it reports accurately on the first call, but incorrectly for every call after. Is there a better way to detect if an executable is running on a workstation?

Thanks,


Please use

Code: Select all | Expand

oExcel := ExcelObj()


ExcelObj() is a FWH function which takes care of whether Excel is already running.
Regards

G. N. Rao.
Hyderabad, India
User avatar
Enrico Maria Giordano
Posts: 8766
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Has thanked: 1 time
Been thanked: 5 times
Contact:

Re: OLE with Excel.

Post by Enrico Maria Giordano »

Jimmy wrote:hi,

i´m not sure how under FiveWin but it is recommend to o:Destroy() -> o:End() an ActiveX "Connection" and NIL it

o:Quit() is like close Firefox but still have Internet "Connection"


No, it is not. Quit() method is enough to ensure your instance of Excel is completely removed from memory. Just check it with Task Manager.
Post Reply