View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
kkknie[_165_] kkknie[_165_] is offline
external usenet poster
 
Posts: 1
Default Modifying text files with VBA?

This may not be exactly what you want, but it should be a start

Code
-------------------
Sub bubb()

'I have two (ASCII) text files (FileA and FileB), and I need to replace
'a portion of FileA with the contents of FileB. The position of the
'text in the files is fixed - I just need to replace lines 274-326 in
'FileA with lines 1-53 of FileB.

Dim strLine1 As String
Dim strLine2 As String
Dim strLines(10000) As String
Dim i As Long
Dim iMax As Long
Dim bFound As Boolean

Close
Open "c:\file1.txt" For Input As #1
i = 0
bFound = False
Do Until EOF(1)
i = i + 1
Line Input #1, strLine1
If i < 274 Or i 326 Then
strLines(i) = strLine1
Else
If bFound = False Then
bFound = True
Open "c:\file2.txt" For Input As #2
Do Until EOF(2)
Line Input #2, strLine2
strLines(i) = strLine2
Loop
Close #2
End If
End If
Close #1
iMax = i

Open "c:\file3.txt" For Output As #3

For i = 1 To iMax
Print #3, strLines(i)
Next

Close #3

End Su
-------------------




--
Message posted from http://www.ExcelForum.com