Something like this should work.
Option Explicit
Public Function IsWordRunning() As Boolean
IsWordRunning = GetObject("winmgmts:\.
ootcimv2").ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'WINWORD.EXE'").Count > 0
End Function
Public Sub Example()
Debug.Print IsWordRunning()
End Sub
A quick bonus, this could be extended for an Executable name if you like.
Public Function IsProcessRunning(ExecutableName As String) As Boolean
IsProcessRunning = GetObject("winmgmts:\.
ootcimv2").ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & ExecutableName & "'").Count > 0
End Function
Example Usage
Public Sub Example()
Debug.Print IsProcessRunning("WINWORD.EXE")
End Sub
Make sure the name you specify in IsProcessRunning()
is the name as it appears in Task Manager.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…