PDA

View Full Version : combine multiple txt files



imranpaddy
11-03-2019, 01:59 AM
hi team

help required

need a macro to combine multiple txt files into one single excel worksheet along with (.txt) file name in column A



Please help. thank is advance.

mana
11-04-2019, 03:58 AM
TSV?


Option Explicit


Sub test()
Dim p As String
Dim fn As String
Dim r As Range

p = CreateObject("wscript.shell").specialfolders("desktop") & "\test\"
fn = Dir(p & "*.txt")

Do While fn <> ""
Set r = Cells(Rows.Count, 2).End(xlUp).Offset(1)
r.Offset(, -1).Value = fn
With ActiveSheet.QueryTables.Add("TEXT;" & p & fn, r)
.TextFileParseType = xlDelimited
.TextFileTabDelimiter = True
.Refresh False
.Delete
End With
fn = Dir
Loop

End Sub



マナ