Your technology certification is waiting. Enroll in Cloud Class ®
'Declare the File name variables
Dim ReadFromFile, SaveToFile
'Declare the file system object variables
Dim objFSO, objReadFile, ObjCreateFile, objWriteFile
'Declare the source data variable
'Set the name and path of the file we are reading from
'Set the name and path to the file we are writing to (Creating)
'Create and/or open the files to work with
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objReadFile = objFSO.OpenTextFile(ReadFromFile)
Set objCreateFile = objFSO.CreateTextFile(SaveToFile)
Set objWriteFile = objFSO.OpenTextFile(SaveToFile, 2, True)
'Read every line of the file and append a comma to the end of every line.
Do Until objReadFile.AtEndOfStream
'Put the current line into the SourceData variable and remove any leading and trailing spaces
SourceData = Trim(objReadFile.ReadLine)
'Check if we have any more lines after this one and write the data with or without the comma
If ObjReadFile.AtEndOfStream = False Then
'If we haven't reached the last line yet, make sure to include the comma
objWriteFile.WriteLine (SourceData & ",")
'If we are at the last line, make sure to JUST list the name, no comma
'Close the Files
Set objFSO = Nothing
Open in new window
In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.