im trying to open and close a notepad using vba, the following code works to open, but no idea how to close it, I already tried fso.close and fso.quit but error raise, do you know how to achieve this??
Dim fso As Object
Dim sfile As String
Set fso = CreateObject("shell.application")
sfile = "C:\Users\Universal\Desktop\test.txt"
fso.Open (sfile)
im trying to open and close a notepad using vba, the following code works to open, but no idea how to close it, I already tried fso.close and fso.quit but error raise, do you know how to achieve this??
Dim fso As Object
Dim sfile As String
Set fso = CreateObject("shell.application")
sfile = "C:\Users\Universal\Desktop\test.txt"
fso.Open (sfile)
You can try with this simple code. If can be done in different way if I know the purpose.
Sub QuitNotepad()
On Error Resume Next
'taskkil to terminate process; switch /F forces termination process
'vbHide-> to run command without showing process name
Shell "taskkill /F /IM notepad.exe", vbHide
On Error GoTo 0
End Sub
Sub OpenNotepad()
Dim MyFile As String
MyFile = "d:\aaa.txt"
Shell ("C:\Windows\system32\notepad.exe" & " " & MyFile), vbNormalFocus
End Sub