# Microsoft Office Application Help - Excel Help forum > Excel Programming / VBA / Macros >  > [SOLVED] How Close Excel from CMD prompt?

## Al Franz

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?

----------


## Jake Marx

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

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

----------


## Jake Marx

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]

----------


## Scott

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]
>
>

----------


## Dave Peterson

Thanks to both you and Jake.

Here's a link that describes the parms:
http://www.microsoft.com/resources/d.../taskkill.mspx
(one line in your browser)

And searching the web for alternatives (for WinNT 4.x):
http://www.computing.net/windowsnt/w...rum/22493.html

And a free alternative:
http://www.sysinternals.com/Utilities/PsTools.html
or directly...
http://www.sysinternals.com/Utilities/PsKill.html


Scott wrote:
>
> 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]
> >
> >

--

Dave Peterson

----------


## Ivan F Moala

Another option to close Excel using WMI
NB: Si,ilar to Jakes in that it terminates as per Taskmanager




```
Please Login or Register  to view this content.
```


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® Windows 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...N-US/wmi9x.exe

----------

