Create and Save Text file : Text File « File Path « VBA / Excel / Access / Word






Create and Save Text file

 
Private Sub Update()
    Dim myFileSystemObject As FileSystemObject
    Dim myFile As Object
    On Error Resume Next
    
    Set myFileSystemObject = New FileSystemObject
    Set myFile = myFileSystemObject.GetFile("C:\MyCust.txt")
    
    If Err.Number = 0 Then
        Set myFile = myFileSystemObject.OpenTextFile("C:\MyCust.txt", 8)
    Else
        Set myFile = myFileSystemObject.CreateTextFile("C:\MyCust.txt")
    End If
    myFile.WriteLine "File Created on: " & Date & " " & Time
    
    myFile.Close
    Set myFileSystemObject = Nothing
End Sub

 








Related examples in the same category

1.Save Date and Time information to a text file
2.Filtering a text file
3.Read a text file, skipping the Total lines
4.Read a text file, adding the amounts
5.Reading Text Files One Row at a Time
6.Use a Do...While loop to keep reading records until you've reached the end of the file:
7.Writing Text Files