Sub GetPID()
Dim StrPath As String
StrPath = "C:\New folder\Test.txt" ' Please type FullName
MsgBox notepad_ProcessID_ByName(StrPath)
End Sub
Public Function notepad_ProcessID_ByName(NtpPath As String)
Dim oServ As Object
Dim cProc As Object
Dim oProc As Object
StrProcessName = "Notepad.exe"
Set oServ = GetObject("winmgmts:")
Set cProc = oServ.ExecQuery("select * from win32_process")
For Each oProc In cProc
If InStr(1, oProc.Name, StrProcessName, vbTextCompare) <> 0 Then ' is it Notepad
If InStr(1, oProc.CommandLine, NtpPath, vbTextCompare) <> 0 Then ' check path
PID = oProc.ProcessID
'oProc.Terminate
Exit For
End If
End If
Next
notepad_ProcessID_ByName = PID
Set oServ = Nothing
Set cProc = Nothing
End Function