DCFirecracker
New Member
- Joined
- Aug 24, 2019
- Messages
- 1
Hi. I need to make sure that Chrome is not running in the background during certain Excel events. I found the following code on a different forum from a thread posted a few years ago. It works (i.e., it calls the macro when the event occurs and closes Chrome) but it also throws a debugging error (i.e., runtime error: not found) related to the objProcess.Terminate line of code. I'm currently running Excel 2016 and I'm pretty new to VBA coding. Does anyone have any suggestions on how to resolve the error?
Sub FindAndTerminate(ByVal strProcName As String)
Dim objWMIService, objProcess, colProcess
Dim strComputer
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '" & strProcName & "'")
If colProcess.Count > 0 Then
For Each objProcess In colProcess
objProcess.Terminate
Next objProcess
End If
End Sub
'Call with:'
'FindAndTerminate "chrome.exe" as part of a worksheet event sub'
Sub FindAndTerminate(ByVal strProcName As String)
Dim objWMIService, objProcess, colProcess
Dim strComputer
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!" _
& strComputer & "\root\cimv2")
Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = '" & strProcName & "'")
If colProcess.Count > 0 Then
For Each objProcess In colProcess
objProcess.Terminate
Next objProcess
End If
End Sub
'Call with:'
'FindAndTerminate "chrome.exe" as part of a worksheet event sub'