Modifying a LARGE text file
Option Explicit
Sub testme01()
Dim TextLine As String
Dim rCtr As Long
Dim myStr As String
Dim WhichRecord As Long
WhichRecord = 10
myStr = Worksheets("Sheet1").Range("A1").Text
'just in case
Close #1
Close #2
'my test files
Open "c:\my documents\excel\book2.txt" For Input As #1
Open "c:\my documents\excel\book2.txt.out" For Output As #2
rCtr = 0
Do While Not EOF(1)
Line Input #1, TextLine
rCtr = rCtr + 1
If rCtr = WhichRecord Then
TextLine = TextLine & myStr
End If
Print #2, TextLine
Loop
Close #1
Close #2
End Sub
I just appended the string, but you could parse it anyway you like.
Fabian Grodek wrote:
I have a large (15000 lines) text file. I want to write a VBA macro to modify
one specific line in that file, say line number 10, replacing the existing
text with some string/values taken from some cell.
Any hint will be greately appreciated.
Fabian
--
Dave Peterson
|