View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips Bob Phillips is offline
external usenet poster
 
Posts: 10,593
Default Reading from Numerous Text Files into Excel Column

Sub Test()
Dim iLastRow As Long
Dim i As Long
Dim oWB As Workbook

Application.ScreenUpdating = False
With ActiveSheet
iLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = 1 To iLastRow
On Error Resume Next
Set oWB = Workbooks.Open(.Cells(i, "A").Value)
On Error GoTo 0
If Not oWB Is Nothing Then
.Cells(i, "B").Value = oWB.Worksheets(1).Range("A1").Value
oWB.Close savechanges:=False
End If
Next i
End With
Application.ScreenUpdating = True

End Sub



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"ep" wrote in message
oups.com...
Hi all, I have a column containing various filenames of text files
which reside in a local folder. I'd like the column next to this to
contain the actual text located inside each file. These text files are
just one line so I don't need a complicated text reader, just something
basic and preferably something that updates when opening the
spreadsheet or perhaps when I hit a button if this will be a macro. I
could do this manually, but there are hundreds of files.

Any suggestions?

Thanks for any help.