Vba Close Notepad

[Solved] Vba Close Notepad | Vb - Code Explorer | yomemimo.com
Question : VBA - Close notepad

Answered by : adorable-albatross-mew0gefbw9tc

Sub test()
Dim StrPath As String
StrPath = "C:\New folder\Test.txt" ' Please type FullName
Call Close_Notepad_ByName(StrPath)
End Sub
Public Sub Close_Notepad_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' check if Notepad If InStr(1, oProc.CommandLine, NtpPath, vbTextCompare) <> 0 Then ' check Path oProc.Terminate End If End If
Next
Set oServ = Nothing
Set cProc = Nothing
End Sub

Source : https://social.msdn.microsoft.com/Forums/office/en-US/d8ea7f9d-fa9a-45ae-a514-c16062481090/how-to-close-an-external-application-notepad?forum=accessdev | Last Update : Wed, 22 Jun 22

Answers related to vba close notepad

Code Explorer Popular Question For Vb