Comma De-Limited

By | 2002-06-01

This code will read a file line by line and create a comma delimited text file which can then be imported into Excel.

Original Author: Howard Lee

Inputs

FileRead = File To be read as input
FileOutPut = file that will be created as output

Code

Private Sub Form_Load ()
Dim instring As String
Dim outstring As String
On Error GoTo Clnup
Open "FileRead.txt" For Input As #1 ' file opened for reading
Open "FileOutPut.txt" For Output As #2 ' file created

Line Input #1, instring
While Not EOF(1)
  Line Input #1, instring
  If Len(outstring) = 0 Then
    outstring = instring
  Else
    outstring = outstring & "," & instring
  End If
  
Wend
Print #2, outstring
Close #1
Close #2
Clnup:
Close
End
End Sub

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.