![]() |
How Close Excel from CMD prompt?
Have an automated Excel routine I run on a PC, but the one problem I have is
that if Excel is already open I get an error if it tries to open excel again. Is there a way to make sure Excel is closed from a Command Prompt in my Batch File? |
How Close Excel from CMD prompt?
Hi Al,
Al Franz wrote: Have an automated Excel routine I run on a PC, but the one problem I have is that if Excel is already open I get an error if it tries to open excel again. Is there a way to make sure Excel is closed from a Command Prompt in my Batch File? IMO it would be better to figure out why this is happening instead of killing Excel. But if you must terminate a process from a batch file, here's how you could do it: taskkill /F /IM EXCEL.EXE Note - this will kill Excel just like it would if you killed it from task manager, so you'll lose anything you had open and unsaved. -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] |
How Close Excel from CMD prompt?
Is taskkill available in all versions of windows?
(Or better, what version of windows are you running?) It wasn't found in WinXP Home edition. Jake Marx wrote: Hi Al, Al Franz wrote: Have an automated Excel routine I run on a PC, but the one problem I have is that if Excel is already open I get an error if it tries to open excel again. Is there a way to make sure Excel is closed from a Command Prompt in my Batch File? IMO it would be better to figure out why this is happening instead of killing Excel. But if you must terminate a process from a batch file, here's how you could do it: taskkill /F /IM EXCEL.EXE Note - this will kill Excel just like it would if you killed it from task manager, so you'll lose anything you had open and unsaved. -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] -- Dave Peterson |
How Close Excel from CMD prompt?
Dave Peterson wrote:
Is taskkill available in all versions of windows? (Or better, what version of windows are you running?) It wasn't found in WinXP Home edition. Interesting...I don't know. I'm running XP Pro SP2. -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] |
How Close Excel from CMD prompt?
According to ITWorld.com, TaskKill is only included in XP Pro.
-- Scott "Jake Marx" wrote: Dave Peterson wrote: Is taskkill available in all versions of windows? (Or better, what version of windows are you running?) It wasn't found in WinXP Home edition. Interesting...I don't know. I'm running XP Pro SP2. -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] |
How Close Excel from CMD prompt?
Another option to close Excel using WMI NB: Si,ilar to Jakes in that it terminates as per Taskmanager Code ------------------- Sub GetNumberOfEXCELProcessesRunning() Dim strComputer As String Dim objWMIService As Object Dim objProcess As Object Dim objList As Object '// Const XL As String = "EXCEL.EXE" '// strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objList = objWMIService.ExecQuery("select * from win32_process where name='" & XL & "'") 'Set objList = objWMIService.execquery("select * from win32_process where name='EXCEL.EXE'") MsgBox "Number of " & XL & " instances:= " & objList.Count '// Do something like .... For Each objProcess In objList ' '// Close Xl down ' objProcess.terminate Next Set objWMIService = Nothing Set objList = Nothing Set objProcess = Nothing End Sub ------------------- Currently, WMI is included when you install; Microsoft® Windows® 2000, Windows XP, Windows Millennium Edition (Me). For those running Windows 95 OSR 2, Windows 98 or Microsoft® Window NT® 4.0, a WMI installation package can be downloaded from Microsoft MSDN® which offers similar functionality as WMI in Windows 2000 Windows XP, and Windows Me. http://download.microsoft.com/downlo...EN-US/wmi9x.ex -- Ivan F Moal ----------------------------------------------------------------------- Ivan F Moala's Profile: http://www.excelforum.com/member.php...nfo&userid=195 View this thread: http://www.excelforum.com/showthread.php?threadid=39736 |
All times are GMT +1. The time now is 08:04 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com