Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

draw data in from text file

12 views
Skip to first unread message

john taiariol

unread,
Oct 29, 2022, 12:33:25 PM10/29/22
to
Hi,
I have a folder with several .txt files in it. I would like VBA code to bring the data into one column of an excel file without me having to open each file and copy paste thanks.

Auric__

unread,
Nov 2, 2022, 2:29:49 AM11/2/22
to
Try this. It puts everything in the currently-selected column, starting with
the currently-selected cell.

Sub aaa()
Dim fName As String, inP As String, txt As Variant, L0, cntr
fName = Dir$("*.txt")
While fName <> ""
Open fName For Binary As 1
inP = Space$(LOF(1))
Get #1, 1, inP
Close 1
txt = Split(inP, vbNewLine)
For L0 = 0 To UBound(txt)
ActiveCell.Offset(cntr).Value = txt(L0)
If 0 = (L0 Mod 100) Then Application.StatusBar = L0: DoEvents
cntr = cntr + 1
Next
fName = Dir$
Wend
Application.StatusBar = False
End Sub

--
Touchdown confirmed.
We are safe on Mars.
0 new messages