View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default multiple text files to multiple rows in excel

Sub GetLine4()

Const folder = "c:\Temp\Test"
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Dim fs, f

Set fs = CreateObject("Scripting.FileSystemObject")

RowCount = 1
Do While Range("A" & RowCount) < ""
Filename = Range("A" & RowCount)
Set f = fs.OpenTextFile(Filename, _
ForReading)
For LineCount = 1 To 3
f.readline
Next LineCount
InputLine = f.readline
Range("B" & RowCount) = InputLine
f.Close
RowCount = RowCount + 1
Loop

End Sub


"Vindhyawasini" wrote:

Hi,
I have an excel sheet containing two columns "Text File Name" & "Text File
Content", there are more than 2000 rows. On my hard disk there is a folder in
which all the text files are stored. I have to import Line number 4 from text
files in the cell next to "Text File Name". The format of the excel sheet is
as below:
TEXT FILE NAME TEXT FILE CONTENT
File_1 (This content is needed from text
"File_1")
File_2 (This content is needed from text
"File_2")
File_3 (This content is needed from text
"File_3")
..........
I hope to find a proper solution here.
Thanks.