I am trying to get free form user input using a text box and print it to text file. Objective is to write into a text file with fixed length, say length=25, While writing the text, if a word is getting cut in between (if it could not be accommodated within the record length), then the complete word should be written to next line. Note: I have already tried the options of .prn and have skimmed through the forum.
Example:
User Input in textbox : This is a sample file Please feel free to edit.
Expected Pattern in output text file:
This is a sample file
Please feel free to edit.
Code
-------------------------------------------
Sub textBox1_Change()
Dim fso As FileSystemObject
Dim stream As TextStream
Dim Q1A1 As String
Set fso = New FileSystemObject
Set stream = fso.CreateTextFile("C:\Temp\Test.txt", True)
Q1A1 = textBox1.Value
stream.Write "The Answer for Question-1 is below" & vbCrLf
stream.WriteLine Q1A1 & vbCrLf
stream.Close
End Sub
Bookmarks