Create a Text File at given path

Share this post
FaceBook  Twitter  Mixx.mn     

To Create a Text File at given path, use following code:
Steps:
1) Create a FileSystem Object

2) Delete file if already exist  

3) Open text file

4) write Text file

5) Close file

Code:

'Create a Text File at given path
'==============================================
Function Create_TextResults_File(FilePath)
'1) Create a FileSystem Object
Set fso = CreateObject("Scripting.FileSystemObject")

'2) Delete file if already exist '
If fso.FileExists(FilePath) Then
   fso.DeleteFile FilePath
End If

'3) Open text file'
Set f =fso.CreateTextFile(FilePath, True)
'Set f1 = fso.OpenTextFile(FilePath, ForWriting, True) 'Creating

'4) write Text file'
f.WriteLine "Test Data1"
f.WriteLine "Test Data2"

'5) Close file
'
f.close
End Function