Ending Excel processes in VBA

gorgon777

Board Regular
Joined
Mar 12, 2012
Messages
58
Hi again,

I have the following code to stop Excel processes running
Rich (BB code):
Sub Kill_Excel()

Dim sKillExcel As String

sKillExcel = "TASKKILL /F /IM Excel.exe"
Shell sKillExcel, vbHide

End Sub

But this also closes the main workbook. Is there a way to stop that from happening, as I only want to close those processes left trailing from the CreateObject method I use in my code.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Rather than kill the entire Excel process, would it not be better to set the old instances of objects to nothing?

e.g.
Set MyObj = Nothing

change MyObj to the object you are trying to close.

Andrew
 
Upvote 0
The topic offers useful solution to end Excel processing in VBA.

Following demo code is I copied from that thread for Excel processing issue.
Code:
Option Explicit  Private Sub Application_Startup() Dim xlApp As Excel.Application Dim myWB As Excel.Workbook Dim myDate As Date Dim myPrompt As Variant      myDate = Date      Set xlApp = CreateObject("Excel.Application")      xlApp.Visible = False      Set myWB = xlApp.Workbooks.Open("C:\Users\JThomps2\Desktop\ClosingDays.xls")      myPrompt = xlApp.VLookup(CDbl(myDate), myWB.Worksheets("Sheet1").Range("A:B"), 2, False)         If Not IsError(myPrompt) Then         MsgBox ("Closing Day " & myPrompt)     End If          myWB.Close False        Set myWB = Nothing      xlApp.Quit      Set xlApp = Nothing  End Sub

http://www.mrexcel.com/forum/excel-questions/735062-excel-process-not-closing.html
 
Last edited:
Upvote 0
Andrew's solution worked great:) The reason I kept having trailing processes was because I forgot to do it to every workbook I opened.
 
Upvote 0

Forum statistics

Threads
1,223,700
Messages
6,173,909
Members
452,536
Latest member
Chiz511

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top