Terminaing an Instance of Excel

R

rg

Where do I find VBA code that not only will detect an instance of Excel
running but will terminate it?

Thank you.

Roy
 
M

MikeB77

if you don't care about saving the open worksheets try this:

Function killAllXL() 'superkiller for remaining excel instances
' On Error Resume Next
Dim objs As Object
Dim obj As Object
Dim strSQL As String
Dim strWMI As String
strWMI = "winmgmts:"
strSQL = "Select * From Win32_Process "
strSQL = strSQL & "where Name = 'EXCEL.EXE'"
Set objs = GetObject(strWMI).ExecQuery(strSQL)
For Each obj In objs
obj.Terminate
Next
Set objs = Nothing
End Function


if you do care about open books then loop with:
on error resume next
Set oXL = GetObject(, "Excel.Application")
if not oXL is noting then... save eit and exit

but his will not close an instance with open references (e.g., an object set
to range within) so after a bit (counter = 10) do the kill thing above.
crude but works for me.

mb

"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top