Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Howto close all Excel Applications
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00485601
Message ID:
00485866
Views:
10
Mark,

The main purpose why I want to use WINAPI instead of Excel Automation is that sometimes while initiating like createobj("Excel.automation") or getobject(,"Excel.Automation") the error occurs that stop some or all Excel processes on the server. I do not know yet what cause it, but the temporary solution I try to implement is to kill all running Excel.exe instantyes.
As you see in my code, if sendmessage() is used with the second parameter equal 16 then the close dialog appears as expected. I thought, that the second parameter 2 should destroy the process without dialog, but instead it gives the error like "memory can not be overwritten..".

Anyway thanks for your input.



>>>>>>>>previous messages below
>John and Mark,
>
>Thank you both of you for your replay. Sure in my applications I can control it. But my question is related to the Excel/Word applications which are created by another developers. I do not know what programming technic/language they use. I have the window handle only (oWordHandle from my code). So, how to close Excel Application unconditionally having oWordHandle?
>
>
>>>>>>>>>>>>>>previous messages below
>>Sometimes I need to close unconditionally all running Excel or Word applications on the remote server. I do it as described in http://support.microsoft.com/support/kb/articles/Q246/0/21.ASP, like:
>>*------------------------
>>DECLARE LONG FindWindowA IN WIN32API STRING class, STRING title
>>DECLARE INTEGER SendMessage IN Win32API ;
>> INTEGER HWND,INTEGER Msg, Short WParam, INTEGER LPARAM
>>
>>* Pass the class name for Excel - "XLMain" to FindWindowA
>>lcMSClassName="XLMain"
>>
>>oWordHandle = FindWindowA(lcMSClassName,NULL)
>>do while oWordHandle>0
>> =SendMessage(oWordHandle,16,0,0)
>> oWordHandle = FindWindowA(lcMSClassName,NULL)
>>enddo
>>*----------------------------
>>The problem is when changes were made on particular file, the messagebox appears asking for "do you want to save..." and waiting for response.
>>In all my applications I use objExcel.DisplayAlerts=.f. to avoid it, but I can not figure out how to control others.
>>I will appreciate your help.
>ActiveWorkbook.Saved = .T. will close Excel without a prompt.
>Mark

Ok, then you can do that like this:
1. Use FindWindowA to find out if any copy of Excel is running
2. oleApp = GETOBJECT(, "Excel.Application")
oleApp.ActiveWorkbook.saved = .T.
oleApp.Quit()

Mark
MCP VFP
Previous
Reply
Map
View

Click here to load this message in the networking platform