Page 1 of 1

Ole Excel : closing aplication with sendmessage(hwnd,16)

Posted: Tue Jan 01, 2008 2:48 pm
by demont frank
Hello,

I try to use

oExcel := CreateObject( "Excel.Application" ) , followed with

oExcel:WorkBooks:Add()
oAs := oExcel:ActiveSheet()

After making it visible (oExcel:Visible := .T.) , the user can close aplication or return to the aplication without closing it.

I noticed that excel is executed with caption .... MAP1 ...

Next code can detect that excel is not closed , but closing it fails :

Code: Select all

hWnd := FINDWND( "MAP1" )

IF !EMPTY( hWnd )
  SENDMESSAGE( hWnd, 16 )
  //CloseWindow(hWnd)
END


#define GW_HWNDNEXT  2
#define GW_CHILD     5

FUNCTION FINDWND( cTitle )

 LOCAL hWnd := GETWINDOW( GETDESKTOPWINDOW(), GW_CHILD )

WHILE hWnd != 0
  IF UPPER( cTitle ) $ UPPER( GETWINDOWTEXT( hWnd ) )
    RETURN hWnd
  ENDIF
  hWnd = GETWINDOW( hWnd, GW_HWNDNEXT )
ENDDO

RETURN NIL

How can excel be closed ?

Must the object oExcel released ? How

Frank

Posted: Tue Jan 01, 2008 2:51 pm
by demont frank
Little corection : excel ask to save , when yes it is closed

Posted: Tue Jan 01, 2008 4:47 pm
by Kleyber
Hi Frank,

I would do at the end of function:

oExcel:=NIL

Best regards and a Happy New Year

Re: Ole Excel : closing aplication with sendmessage(hwnd,16)

Posted: Tue Jan 01, 2008 6:42 pm
by Enrico Maria Giordano
You have oExcel. So you can use it to close Excel:

oExcel:Quit()

EMG

Posted: Tue Jan 01, 2008 6:42 pm
by Enrico Maria Giordano
Kleyber wrote:Hi Frank,

I would do at the end of function:

oExcel:=NIL

Best regards and a Happy New Year
No, it is not needed.

EMG

Hello, from Germany

Posted: Tue Jan 01, 2008 7:40 pm
by ukoenig
Yust have a look at my sample < Excel-Matrix >
you can download it from
http://pflegeplus.com/fivewin
or have a look at forum => utilities

U.König :lol: