Hi,
I need to know how can I save Notepad document that i Open with VBA , i found the code to close Notepad but Saveas don't work, I can offcorse use Sendkey but it is not recommended method and I would really want to use CreateObject("Word.Application") method to save it
I got a code from this thread http://www.mrexcel.com/forum/excel-questions/715607-closing-notepad-visual-basic-applications.html
but author seem to have not connected for some time now, so I am creating new thread for help;
Thanks in advance for all your help
I need to know how can I save Notepad document that i Open with VBA , i found the code to close Notepad but Saveas don't work, I can offcorse use Sendkey but it is not recommended method and I would really want to use CreateObject("Word.Application") method to save it
I got a code from this thread http://www.mrexcel.com/forum/excel-questions/715607-closing-notepad-visual-basic-applications.html
but author seem to have not connected for some time now, so I am creating new thread for help;
Thanks in advance for all your help
Code:
Public Sub CloseNotepad()
Dim oWdApp As Word.Application
Dim oTask As Task
Dim bCreate As Boolean
On Error Resume Next
Set oWdApp = GetObject(, "Word.Application")
On Error GoTo 0
If oWdApp Is Nothing Then
Set oWdApp = CreateObject("Word.Application")
oWdApp.Visible = False
bCreate = True
End If
For Each oTask In oWdApp.Tasks
'Provide a condition here which will match the notepad instances created by your code!
If InStr(oTask.Name, "Notepad") > o Then
oTask.Close
End If
Next
If bCreate Then oWdApp.Quit
End Sub