LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Writing to a text file

This part of Jim's code:

Line Input #1, TextLine
Print #2, TextLine
Print #2, "Inserted text"
Do While Not EOF(1)
Line Input #1, TextLine
Print #2, TextLine
Loop

Reads the first record, writes it out, then writes that "inserted text" line.

Then it just keeps reading/writing each input record.

If you wanted the insertion after the 22nd record, you could just count when you
read in the records.

Option Explicit
Sub a2()

Dim TextLine As String
Dim recCtr As Long

recCtr = 0

Open "c:\file.txt" For Input As #1
Open "c:\newfile.txt" For Output As #2

Do While Not EOF(1)
Line Input #1, TextLine
recCtr = recCtr + 1
Print #2, TextLine
If recCtr = 22 Then
Print #2, "Inserted text"
End If
Loop

Close #1
Close #2

Kill "c:\file.txt"

Name "c:\newfile.txt" As "c:\file.txt"

End Sub

scantor145 wrote:

Thanks, but I don't understand how the new text is being inserted into
the second line. What if I want the text to be inserted after line 22?

--
scantor145
------------------------------------------------------------------------
scantor145's Profile: http://www.excelforum.com/member.php...o&userid=14766
View this thread: http://www.excelforum.com/showthread...hreadid=383308


--

Dave Peterson
 
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
Writing to a text file Rachel Curran Excel Programming 0 October 8th 04 09:44 AM
Writing strings to a text file ? Dan Thompson Excel Programming 3 September 23rd 04 07:17 PM
Writing to a text file some data Tom Ogilvy Excel Programming 0 September 9th 04 04:25 PM
WRITING TO A TEXT FILE WITH SPECIFIC FORMAT [email protected] Excel Programming 2 December 27th 03 05:04 AM
Writing multilines to a text file without closing ccdubs Excel Programming 1 July 10th 03 07:43 AM


All times are GMT +1. The time now is 11:08 AM.

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

About Us

"It's about Microsoft Excel"