CreateTextFile method
Creates a specified file and returns a TextStream object that can be used to read or write the created file.
object.CreateTextFile(filename[, overwrite[, unicode]])
Parameters
Object
Required option. Should be the name of the FileSystemObject or Folder object.
FileName
Required option. A string expression that indicates the file to create.
Overwrite
Options available. A Boolean value that indicates whether an existing file can be overwritten. TrueIf the file can be overwritten, or False If the file cannot be overwritten. If this value is omitted, the existing file cannot be overwritten.
Unicode
Options available. A Boolean value that indicates whether the file is created in Unicode or ASCII file format. TrueIf the file is created in a Unicode file format, FalseIf the file is created in an ASCII file format. If this section is omitted, the ASCII file is assumed to be created.
Description
The following code illustrates how to use the CreateTextFile method to create and open a text file:
Sub CreateAfile Dim fso, MyFile Set fso = CreateObject("Scripting.FileSystemObject") Set MyFile = fso.CreateTextFile("c:\testfile.txt", True) MyFile.WriteLine("
This is a test.")
MyFile.Close
End Sub
For files where filename already exists, an error occurs if the overwrite argument is Falseor if this parameter is not supplied.