ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to add data into a text file without overwriting existing data (https://www.excelbanter.com/excel-programming/392259-how-add-data-into-text-file-without-overwriting-existing-data.html)

J@Y

How to add data into a text file without overwriting existing data
 
I'm using

Print FileNumber, LineofText

to copy one line of text from one text file to another text file. If I close
the file and reopen them to write again, the previous data gets erased. How
do I open the write file so what is already in it stays and what I add to it
follows ?

Chip Pearson

How to add data into a text file without overwriting existing data
 
What you didn't include in your message was your Open statement. If you open
the destination file for Output, existing contents are destroyed. If you
open it for Append, new content is added to the end of the file.

Open "C:\Test.txt" For Append Access Write As #FileNum


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"J@Y" wrote in message
...
I'm using

Print FileNumber, LineofText

to copy one line of text from one text file to another text file. If I
close
the file and reopen them to write again, the previous data gets erased.
How
do I open the write file so what is already in it stays and what I add to
it
follows ?



J@Y

How to add data into a text file without overwriting existing
 
Excellent. Thanks, the Append worked.

"Chip Pearson" wrote:

What you didn't include in your message was your Open statement. If you open
the destination file for Output, existing contents are destroyed. If you
open it for Append, new content is added to the end of the file.

Open "C:\Test.txt" For Append Access Write As #FileNum


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"J@Y" wrote in message
...
I'm using

Print FileNumber, LineofText

to copy one line of text from one text file to another text file. If I
close
the file and reopen them to write again, the previous data gets erased.
How
do I open the write file so what is already in it stays and what I add to
it
follows ?




All times are GMT +1. The time now is 04:41 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com