ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Reading from Numerous Text Files into Excel Column (https://www.excelbanter.com/excel-programming/377045-reading-numerous-text-files-into-excel-column.html)

ep

Reading from Numerous Text Files into Excel Column
 
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.


Bob Phillips

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.





All times are GMT +1. The time now is 02:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com