Wednesday, February 9, 2011

Script to Write a text in a file

'Write to existing text file
On Error Resume Next
dim objFSO
dim objFile

Const ForWriting=2
'specify filename and path for file to open
strFile="c:\file.txt"

set objFSO=CreateObject("Scripting.FileSystemObject")
'if file already exists, value of TRUE forces overwriting file
set objFile=objFSO.OpenTextFile(strFile,ForWriting)
objFile.WriteLine Now & " this is a new line"

objFile.Close

set objFile=Nothing
set objFSO=Nothing

No comments: