FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour OLE with Excel.
Posts: 408
Joined: Sun Nov 06, 2005 03:55 PM
OLE with Excel.
Posted: Tue Oct 18, 2022 06:07 PM

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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: OLE with Excel.
Posted: Tue Oct 18, 2022 07:20 PM

Can you prepare a little sample showing the problem that can be compiled and run?

Posts: 408
Joined: Sun Nov 06, 2005 03:55 PM
Re: OLE with Excel.
Posted: Tue Oct 18, 2022 07:58 PM

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
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: OLE with Excel.
Posted: Tue Oct 18, 2022 09:12 PM
This is a working sample:

Code (fw): Select all Collapse
#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
Posts: 408
Joined: Sun Nov 06, 2005 03:55 PM
Re: OLE with Excel.
Posted: Tue Oct 18, 2022 09:24 PM

Thank you, I will give this a shot.

Thanks,

Byron Hopp

Matrix Computer Services
Posts: 408
Joined: Sun Nov 06, 2005 03:55 PM
Re: OLE with Excel.
Posted: Tue Oct 18, 2022 09:28 PM

Works Great, Thank you,

Thanks,

Byron Hopp

Matrix Computer Services
Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: OLE with Excel.
Posted: Tue Oct 18, 2022 09:43 PM
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 (fw): Select all Collapse
   // Start Excel
   oExcel := CreateObject( "Excel.Application" )

   ...

   // Quit Excel
   oExcel:Quit()
   // destroy the reference
   oExcel:destroy()
   oExcel := NIL
   IF ComLastError() > 0
greeting,

Jimmy
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: OLE with Excel.
Posted: Tue Oct 18, 2022 09:50 PM

oExcel:Quit() is enough.

Posts: 1772
Joined: Thu Sep 05, 2019 05:32 AM
Re: OLE with Excel.
Posted: Tue Oct 18, 2022 10:46 PM

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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: OLE with Excel.
Posted: Tue Oct 18, 2022 11:52 PM
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 (fw): Select all Collapse
oExcel := ExcelObj()


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



G. N. Rao.

Hyderabad, India
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: OLE with Excel.
Posted: Wed Oct 19, 2022 07:49 AM
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.

Continue the discussion