Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 205
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read all lines from a text file into cells C10:Cxxx ? Claudia d'Amato Excel Discussion (Misc queries) 1 September 22nd 09 01:11 PM
Copying certain lines from a text file Michael A Excel Discussion (Misc queries) 3 February 13th 07 08:08 PM
Importing data from a Text File, Not enough lines? baldyguy Excel Programming 1 June 1st 04 05:00 PM
how do you skip lines when reading a text file Yaw Bonsu Excel Programming 1 August 29th 03 03:24 PM
FileSystemObject to get last 10 lines of text file. john Excel Programming 11 July 16th 03 03:54 PM


All times are GMT +1. The time now is 05:03 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"