Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
excel97 vba to append lines to text file overwriting last 2 lines
Hi, I want to mod some vba in excel to append new lines of text to a .txt
file but not from the end of the file but from 2 lines back. The last two lines are always of the form <word1 <word2 and will be overwritten by the appended text. Any pointers will be much appreciated as I am out on a limb away from any reference material. |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
excel97 vba to append lines to text file overwriting last 2 lines
Hi Paul,
Hi, I want to mod some vba in excel to append new lines of text to a .txt file but not from the end of the file but from 2 lines back. The last two lines are always of the form <word1 <word2 and will be overwritten by the appended text. Any pointers will be much appreciated as I am out on a limb away from any reference material. VBA's Open For Append only ever writes to the end of a text file. To overwrite some lines, I think the only thing you'll be able to do is to write it as a new file: - Open the original file for reading - Open a new file for writing - Scan through the original file, writing each line to the new file until the <word1 is found - Write the new lines to the new file - Close both files - Delete the original file and rename the new one over it. Regards Stephen Bullen Microsoft MVP - Excel www.oaltd.co.uk |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How to read all lines from a text file into cells C10:Cxxx ? | Excel Discussion (Misc queries) | |||
Copying certain lines from a text file | Excel Discussion (Misc queries) | |||
Importing data from a Text File, Not enough lines? | Excel Programming | |||
how do you skip lines when reading a text file | Excel Programming | |||
FileSystemObject to get last 10 lines of text file. | Excel Programming |