My previous post showed how to use the file dialogs to get a file name. Using the file name we can then open the file for reading or writing to.
To open the file for reading (where openf = full path of the file you want to open):
Open openf For Input As 1
and to open the file for writing to (where savef = full path of the file you want to save to):
Open savef For Output As 2
Once you have the files open you can use a loop to read each line of the file you have opened and write to the output file. The example shown here reads a comma delimited file, and stores each field in an array called linedata. The first field of this array is the changed to read “hello” befre being written to the output file
Do Until EOF(1)
Line Input #1, newline
linedata = Split(newline, “,”)
linedata(0) = “hello”
Print #2, Join(linedata, “,”)
End If
Loop
Once finished, don’t forget to close the files you have opened:
Close #1
Close #2