paste this code into a module then
usage: KillAllWords
which scans processes for open word apps.
Code:
Option Compare Database
Option Explicit
#If Win64 Then 'Public Dclare PtrSafe Function ...AS LONGPTR
Private Declare PtrSafe Function GetCurrentProcessId Lib "kernel32" () As Long
#Else
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
#End If
Public Sub KillAllWords()
KillMyProcess "Word.exe"
End Sub
Private Sub KillMyProcess(ByVal psProcessName As String)
Dim oWMI As Object
Dim oServices As Object
Dim oSvc
Dim sSvcName As String
On Error Resume Next
Set oWMI = GetObject("winmgmts:")
Set oServices = oWMI.InstancesOf("win32_process")
For Each oSvc In oServices
'sSvcName = LCase(Trim(CStr(oSvc.name) & ""))
'Debug.Print oSvc.name
'If InStr(oSvc.name, psProcessName) > 0 Then
'Beep
'End If
If LCase(psProcessName) = LCase(Trim(CStr(oSvc.Name) & "")) Then
oSvc.Terminate
End If
Next
End Sub
Function IsProcessRunning(ByVal psProcess As String) As Boolean
Dim objList As Object
Set objList = GetObject("winmgmts:") _
.ExecQuery("select * from win32_process where name='" & psProcess & "'")
If objList.Count > 0 Then
IsProcessRunning = True
Else
IsProcessRunning = False
End If
End Function
Function IsServiceRunning(ByVal psSvc As String) As Boolean
Dim oWMI As Object
Dim oServices As Object
Dim oSvc
Dim sSvcName As String
Set oWMI = GetObject("winmgmts:")
Set oServices = oWMI.InstancesOf("win32_process")
For Each oSvc In oServices
sSvcName = LCase(Trim(CStr(oSvc.Name) & ""))
'Debug.Print sSvcName
If InStr(oSvc.Name, psSvc) > 0 Then
IsServiceRunning = True
Exit Function
End If
'If LCase(psSvc) = LCase(Trim(CStr(oSvc.name) & "")) Then IsServiceRunning = True
Next
End Function