OLE with Excel.

OLE with Excel.

Postby byron.hopp » Tue Oct 18, 2022 6: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
byron.hopp
 
Posts: 347
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA

Re: OLE with Excel.

Postby Enrico Maria Giordano » Tue Oct 18, 2022 7:20 pm

Can you prepare a little sample showing the problem that can be compiled and run?
User avatar
Enrico Maria Giordano
 
Posts: 8338
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: OLE with Excel.

Postby byron.hopp » Tue Oct 18, 2022 7: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
byron.hopp
 
Posts: 347
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA

Re: OLE with Excel.

Postby Enrico Maria Giordano » Tue Oct 18, 2022 9:12 pm

This is a working sample:

Code: Select all  Expand view
#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
User avatar
Enrico Maria Giordano
 
Posts: 8338
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: OLE with Excel.

Postby byron.hopp » Tue Oct 18, 2022 9:24 pm

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

Re: OLE with Excel.

Postby byron.hopp » Tue Oct 18, 2022 9:28 pm

Works Great, Thank you,
Thanks,
Byron Hopp
Matrix Computer Services
byron.hopp
 
Posts: 347
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA

Re: OLE with Excel.

Postby Jimmy » Tue Oct 18, 2022 9: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: Select all  Expand view
  // 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: 1590
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: OLE with Excel.

Postby Enrico Maria Giordano » Tue Oct 18, 2022 9:50 pm

oExcel:Quit() is enough.
User avatar
Enrico Maria Giordano
 
Posts: 8338
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: OLE with Excel.

Postby Jimmy » 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
User avatar
Jimmy
 
Posts: 1590
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany

Re: OLE with Excel.

Postby nageswaragunupudi » 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: Select all  Expand view
oExcel := ExcelObj()


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

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10259
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: OLE with Excel.

Postby Enrico Maria Giordano » Wed Oct 19, 2022 7: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.
User avatar
Enrico Maria Giordano
 
Posts: 8338
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 15 guests