Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Writing to a text file | Excel Programming | |||
Writing strings to a text file ? | Excel Programming | |||
Writing to a text file some data | Excel Programming | |||
WRITING TO A TEXT FILE WITH SPECIFIC FORMAT | Excel Programming | |||
Writing multilines to a text file without closing | Excel Programming |