How to Kill Excel Processes With VBA

Written by jaime avelar | 13/05/2017
How to Kill Excel Processes With VBA
End processes using Visual Basic for Applications. (Comstock/Comstock/Getty Images)

In computer programming, it's good practice to release all objects from memory when you're done using them to make sure running processes are not left running in the background. Excel processes may stay active when you're programming using the Microsoft Excel Object Library, and Excel application objects are not released. In VBA you can use the "Shell" function to execute "Taskkill" to forcefully end an Excel process.

Launch Microsoft Word, click the "Developer" tab, and click "Visual Basic." Click the "Insert" menu and click "Module" to add a new VBA code module.

Create a new sub procedure by typing the following code:

Private Sub killExcelProcess()

Declare a new variable and define the Excel process:

xlsProcess = "TASKKILL /F /IM Excel.exe"

Type the following line of code to kill the Excel process:

Finish the procedure by typing "End Sub." Press "F5" to run the procedure.

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.