p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Access (http://p2p.wrox.com/forumdisplay.php?f=18)
-   -   end process in task mgr (http://p2p.wrox.com/showthread.php?t=48434)

bab02 September 28th, 2006 07:17 PM

end process in task mgr
 
I have a .mdb that creates a excel spreadsheet. The .mdb saves the spreadsheet and releases excel from memory.

appExcel.close 'close excel application
set appExcel to nothing 'releasing Excel application
set bks to nothing 'releasing the workbook
set wks to nothing 'releasing the worksheet

However, if you open the task mgr after running the script, I still see Excel.exe under the process tab. I have to manually select excel.exe in the task mgr and click end process.

If I dont do this and try tu run the script (in access) again, it error out. Is there another call to end this process programatically from access? Is it an API call?


mmcdonal September 29th, 2006 06:44 AM

You should check for the existence of the process at the beginning of each set of code for using the process, and if it is still running, kill the process first. I am sure that the posters here can show you a more elegant way, but here is the VBScript version that will run in your VBA:

Dim sComputer

sComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel = impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process")
For Each objProcess in colProcesses
    If objProcess.Name = "EXCEL.EXE" Then
           WScript.Echo objProcess.Name
           errReturnCode = objProcess.Terminate()
       End If
Next

I have tested this and it works on a Windows XP box.

HTH

mmcdonal

mmcdonal September 29th, 2006 06:46 AM

Sorry, I left in some error checking code. Here is the code you should use:

Dim sComputer

sComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel = impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process")
For Each objProcess in colProcesses
    If objProcess.Name = "EXCEL.EXE" Then
           errReturnCode = objProcess.Terminate()
       End If
Next


mmcdonal


All times are GMT -4. The time now is 07:48 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.