Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA to open and save text file using notepad

Status
Not open for further replies.

Ken

IS-IT--Management
Jul 13, 2005
68
CA
Hi,

Have written two codes VBA excel 2010 for opening text file in notepad and
save the file.

Did some searching and all the examples shows opening text file in notepad and uses sendkeys to save file. Sendkeys is not working to save notepad file.

file gets opened in notepad, trouble is in saving. the code does not sendkeys to notepad to save file.


Code:
[bold]code 1 [/bold]
Library: Windows Script Host Object model. 
         file connected to it is wshom.ocx

Dim WSHScript as WshShell
set WSHScript = new WSHShell

WSHScript.run "notepad.exe  c:\test\Test1.txt"

' Tried below all option none are responding, 
all responses goes to excel 2010

WSHScript.sendkeys (^s)   
WSHScript.sendkeys (s)
WSHScript.sendkeys (^fs)
WSHScript.sendkeys (%fs)

Code:
[bold]code 2[/bold]
dim shlApp as string

shlApp = "notepad.exe  c:\test\Test1.txt"
call shell(shlApp,vbMaximizedfocus)

' Tried below all option none are responding, 
' all responses goes to excel 2010

sendkeys "^s"
sendkeys "%fs"

Code:
[bold]code 3 [/bold]
Even this is not saving file
open c:\test\Test1.txt for append as freefile
close freefile

Just wanted VBA to open file in notepad and save the notepad file.
What is missing for me to save the notepad file ?


Thanks

Tech
 
Solved it, how to delete this thread.
Tech
 
Techi,

You know how Tek-Tips works. It's a knowledge sharing forum.

Share with your fellow members your solution!

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 

I'm sorry, forgot to add solution. I have used code 2

Code:
dim shlApp as string

shlApp = "notepad.exe  c:\test\Test1.txt"
call shell(shlApp,vbMaximizedfocus)

sendkeys "%fs" , true

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top