Program to read/write text file using filesystemobject
Private Sub Command2_Click()
'read text file and print
Dim fs As FileSystemObject
Dim ts As TextStream
Set fs = New FileSystemObject
If fs.FileExists("C:\Users\Desktop\text1.txt") Then
Set ts = fs.OpenTextFile("C:\Users\Desktop\text1.txt", ForReading, True)
Do While Not ts.AtEndOfStream
strnewlines = strnewlines & ts.ReadLine & vbCrLf
Loop
ts.Close
End If
'for writing into text file
Set ts = fs.OpenTextFile("C:\Users\Desktop\text2.txt", ForWriting, True)
ts.Write strnewlines
End Sub
No comments:
Post a Comment