Question Locked

VBA - How can I add a line of text to the last line of a text file?

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Using VBA (MS Access module), I want to open an existing text file and add a row of text to the end of the file. I cannot seem to accomplish this with a simple Open/Write command... Do I need to use the FileSystemObject? If so, any quick suggestions?

Thanks in advance

3 replies

by polinimz

More simple than I could have hoped, I simply opened the file in APPEND mode as opposed to opening for INPUT...

OPEN "textfile.txt" FOR APPEND as #1

by dr dij

then create a second file, open it and read the recs in first file, writing second either changed or unchanged as needed. and adding any at end.

We use this when we need to backup file.
Then rename the orig to .bak using vb fuctions and rename the new file to the orig.

you can also read the directory and process all files or all files with a certain extension if you need to, opening each or any of them sequentially.

This discussion is closed to new replies.