Save Date and Time information to a text file : Text File « File Path « VBA / Excel / Access / Word






Save Date and Time information to a text file

 
Private Sub m_frm_AfterUpdate()
    Dim myFileSystemObject As FileSystemObject
    Dim myFile As Object
    Dim strFileN As String
    On Error Resume Next

    Set myFileSystemObject = New FileSystemObject
    strFileN = "C:\MyCust.txt"
    Set myFile = myFileSystemObject.GetFile(strFileN)

    If Err.Number = 0 Then
        ' open text file
        Set myFile = myFileSystemObject.OpenTextFile(strFileN, 8)
    Else
        ' create a text file
        Set myFile = myFileSystemObject.CreateTextFile(strFileN)
    End If

    myFile.WriteLine "File Created on: " & Date & " " & Time

    myFile.Close
    Set myFileSystemObject = Nothing
End Sub

 








Related examples in the same category

1.Create and Save 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