Be the first user to complete this post

  • 0
Add to List

FileSystemObject : CreateTextFile Method

Description: 

This function creates a file and returns a TextStream object and later you can use that TextStream object to perform various activity on that file like reading or writing

Format :

objectOfFileSystemObject. CreateTextFile (filename[, overwrite[, unicode]])

  • objectOfFileSystemObject : As the names says, it’s a FileSystemObject.
Arguments: 
  • filename
    • Mandatory
    • Type:     String
    • File will be created with the same name what you will pass here.
  • Overwrite
    • Optional
    • Type: Boolean (True: you can overwrite the file, False for vice versa. By default its False.)
  • · Unicode
    • Optional
    • Boolean (True: File created as Unicode file, False: File created as ASCII file. By default: ASCII file)
Function FnCreateTextFile()        
   Set fso = CreateObject("Scripting.FileSystemObject")

  Set filetxt = fso.CreateTextFile("c:\sample.txt", True)
End Function
  ' So here filetxt will store TextStreamObject in it.



Also Read:

  1. VBA-Excel: Add/Insert multiple objects from a folder in an Excel Document.
  2. FileSystemObject : GetParentFolderName Method
  3. FileSystemObject : GetFileVersion Method
  4. Excel-VBA : Insert Multiple Images from a Folder to Excel Cells
  5. FileSystemObject : CreateFolder Method