Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default 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?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default 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]

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default 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]

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 577
Default 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]




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
File/Close automatically saving changes without prompt Joe@SAA Excel Discussion (Misc queries) 0 June 23rd 08 10:31 PM
Macro to close workbook with prompt JMac[_2_] Excel Worksheet Functions 1 January 31st 08 05:29 PM
Macro to Prompt User to Close After Saving Rutabaga Excel Discussion (Misc queries) 2 July 12th 07 12:38 AM
Save Changes Prompt at close Johnewally Excel Discussion (Misc queries) 2 March 17th 05 09:15 PM
Excel close/save/prompt problem clayton[_2_] Excel Programming 4 January 21st 04 11:45 PM


All times are GMT +1. The time now is 02:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"